![](/img/trans.png)
[英]Intent filter of broadcast receiver for off screen registered manually but not working?
[英]Android - Broadcast Receiver screen off to Intent, not working…?
我下面有插入我的onCreate方法中的代碼,但是它似乎起作用。 我希望它在屏幕關閉/按下電池按鈕時啟動其他活動。
碼:
protected void onStartCommand() {
// TODO Auto-generated method stub
super.onStart();
ScreenReceiver();
}
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
lock.reenableKeyguard();
Intent s = new Intent(Activity1.this , Activity2.class);
startActivity(s);
}
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
lock.disableKeyguard();
}
}
}
任何幫助將不勝感激?
在嘗試啟動該活動之前,您需要獲取WakeLock
。
請參閱此處的CommonsWare答案android AlarmManager不喚醒電話
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.