android.intent.action.SCREEN_ON不作为接收方的意图过滤器工作不作为、过滤器、意图、工作

2023-09-12 02:09:31 作者:越长大越孤单

我试图让一个BroadcastReceiver调用当屏幕开启时。在我的Andr​​oidManifest.xml我指定了:

 <接收器的Andr​​oid版本:NAME =IntentReceiver>
                    <意向滤光器>
                            <作用机器人:名称=android.intent.action.SCREEN_ON>< /作用>
                    &所述; /意图滤光器>
                < /接收器>
 

不过似乎接收机从未引用(断点不火,登录忽略的语句)。我已经换出SCREEN_ON为BOOT_COMPLETED的测试,而这个的确实的被调用。

这是一个1.6(SDK 4级)的项目。

Android Intent Action 大全

有一个谷歌code搜索发现这一点,我下载了该项目,并同步它,将它转换与最新的工具来工作,但它也无法拦截事件。

http://www.google.com/$c$csearch/p?hl=en#_8L9bayv7qE/trunk/phxandroid-intent-query/AndroidManifest.xml&q=android.intent.action.SCREEN_ON

时这也许不再支持?

previously我已经能够成功地截获此事件与调用Context.registerReceiver()像这样

  registerReceiver(新BroadcastReceiver的(){

  @覆盖
  公共无效的onReceive(上下文的背景下,意图意图){
    // ...
  }
},新的IntentFilter(Intent.ACTION_SCREEN_ON));
 

然而,这是由一个长生活服务执行。继CommonsWare明智的建议我已经当选为尽量去除长期生活服务,并使用不同的技术。但我仍然需要检测屏幕和关闭事件。

解决方案   

继CommonsWare明智的建议   我已经选择尽量去除   长期生活服务,并使用不同   技术。

其实,我相信我的建议是多了一个淡蓝色的...: - )

  

但我仍然需要检测屏幕   和关闭的事件。

有说Android不希望启动新进程的某些事件,因此该设备没有得到来自各种东西都必须同时运行太慢了。 ACTION_SCREEN_ON 就是其中的一个。看到这个$p$pvious问题了解有关该主题的淡蓝色的建议。

所以,你需要问自己,自我,我真的需要得到这些事件的控制?。核心Android团队想,如果你的答案是不。

I'm trying to get a BroadcastReceiver invoked when the screen is turned on. In my AndroidManifest.xml I have specified :

                <receiver android:name="IntentReceiver">
                    <intent-filter>
                            <action android:name="android.intent.action.SCREEN_ON"></action>
                    </intent-filter>
                </receiver>

However it seems the receiver is never invoked (breakpoints don't fire, log statements ignored). I've swapped out SCREEN_ON for BOOT_COMPLETED for a test, and this does get invoked.

This is in a 1.6 (SDK level 4) project.

A Google Code Search revealed this, I downloaded the project and synced it, converted it to work with latest tools, but it too is not able to intercept that event.

http://www.google.com/codesearch/p?hl=en#_8L9bayv7qE/trunk/phxandroid-intent-query/AndroidManifest.xml&q=android.intent.action.SCREEN_ON

Is this perhaps no longer supported?

Previously I have been able to intercept this event successfully with a call to Context.registerReceiver() like so

registerReceiver(new BroadcastReceiver() {

  @Override
  public void onReceive(Context context, Intent intent) {
    // ... 
  }
}, new IntentFilter(Intent.ACTION_SCREEN_ON));

However this was performed by a long-living Service. Following sage advice from CommonsWare I have elected to try to remove the long-living Service and use different techniques. But I still need to detect the screen off and on events.

解决方案

Following sage advice from CommonsWare I have elected to try to remove the long-living Service and use different techniques.

Actually, I believe my advice was more of a light blue... :-)

But I still need to detect the screen off and on events.

There are certain events that Android does not want to start up new processes for, so the device does not get too slow from all sorts of stuff all having to run at once. ACTION_SCREEN_ON is one of those. See this previous question for light blue advice on that topic.

So, you need to ask yourself, "Self, do I really need to get control on those events?". The core Android team would like it if your answer was "no".