BroadcastReceiver的对屏幕锁没有被触发
问题描述:
我试图把GPS位置更新了屏幕锁定时。读了这个问题的答案Android - 如何接收广播意图ACTION_SCREEN_ON / OFF
I'm trying to turn the GPS location updates off when the screen locks. Having read the answer to this question Android - how to receive broadcast intents ACTION_SCREEN_ON/OFF?
我已经写了一些code来实现一个BroadcastReceiver,但是当屏幕熄灭它不工作。
I've written some code to implement a BroadcastReceiver but it's not working when the screen goes off.
我注册一个BroadcastReceiver在我的code与
I've registered a BroadcastReceiver in my code with
@Override
public void onResume() {
super.onResume();
IntentFilter iFilter = new IntentFilter();
iFilter.addAction("android.intent.action.ACTION_SCREEN_ON");
iFilter.addAction("android.intent.action.ACTION_SCREEN_OFF");
registerReceiver(screenStatReceiver, iFilter);
和接收器本身只是一个存根现在:
and the receiver itself is just a stub for now:
public BroadcastReceiver screenStatReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.d("BCAST_TAG", "Got broadcast");
String action = intent.getAction();
}
};
和在清单中我有:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
任何想法,当我在我的手机调试它,为什么它没有被触发?
Any ideas as to why it's not being triggered when I debug it on my phone?
答
看看这个教程Handling屏幕关闭,并在意向