Android的 - 如何接收广播意图ACTION_SCREEN_ON / OFF?意图、Android、OFF、ACTION_SCREEN_ON

2023-09-11 12:14:26 作者:时光凉丷春衫薄

    <application>
         <receiver android:name=".MyBroadcastReceiver" android:enabled="true">
                <intent-filter>
                      <action android:name="android.intent.action.ACTION_SCREEN_ON"></action>
                      <action android:name="android.intent.action.ACTION_SCREEN_OFF"></action>
                </intent-filter>
         </receiver>
...
    </application>

MyBroadcastReceiver 设置只是吐FOO的日志。什么都不做。 有什么建议吗?我是否需要指定任何权限赶上意图是什么?

MyBroadcastReceiver is set just to spit foo to the logs. Does nothing. Any suggestions please? Do I need to assign any permissions to catch the intent?

推荐答案

我认为,这些行为只能通过在Java中code(注册接收机通过 registerReceiver()接受),而不是通过在清单中注册的接收器。

I believe that those actions can only be received by receivers registered in Java code (via registerReceiver()) rather than through receivers registered in the manifest.