BroadcastReceiver的对屏幕锁没有被触发 [英] BroadcastReceiver for screen lock not being triggered

查看:157
本文介绍了BroadcastReceiver的对屏幕锁没有被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把GPS位置更新了屏幕锁定时。读了这个问题的答案<一个href="http://stackoverflow.com/questions/1588061/android-how-to-receive-broadcast-intents-action-screen-on-off">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?

推荐答案

看看这个教程<一个href="http://thinkandroid.word$p$pss.com/2010/01/24/handling-screen-off-and-screen-on-intents/">Handling屏幕关闭,并在意向

这篇关于BroadcastReceiver的对屏幕锁没有被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆