android:用于屏幕和屏幕關閉的廣播接收器我只是想知道是否可以在應用程序清單中注冊檢測屏幕ON / OFF的廣播接收器。我不喜歡可編程方法的原因是它需要運行應用程序以便檢測這樣的事情,同時:“當Intent是Intent時,在清單中注冊的廣播接收器的應用程序不必運行廣播接收器執行“(來源:專業Android 2應用程序開發書)我的應用程序實際上是一個鎖屏應用程序,通過使用可編程方式需要一直運行:S有辦法解決嗎?我在清單中嘗試以下內容:<receiver android:name=".MyBroadCastReciever">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
</intent-filter></receiver>和簡單的MyBroadCastReciever類:public class MyBroadCastReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.i("Check","Screen went OFF");
Toast.makeText(context, "screen OFF",Toast.LENGTH_LONG).show();
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.i("Check","Screen went ON");
Toast.makeText(context, "screen ON",Toast.LENGTH_LONG).show();
}
}}
添加回答
舉報
0/150
提交
取消