ACTION_USER_PRESENT,ACTION_SCREEN_ON,ACTION_BOOT_COMPLETED的广播接收器

Ank*_*ain 6 android broadcastreceiver android-manifest

我正在创建一个使用广播接收器的类.我希望在解锁手机时收到广播.但是有一些问题.请帮帮我.

我的Manifest.xml是: -

<receiver android:name=".MyReciever">
    <intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.ACTION_USER_PRESENT" />
            <action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
            <action android:name="android.intent.action.ACTION_SCREEN_ON" />
        </intent-filter>
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

和我的广播接收班: -

public class MyReiever extends BroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {
   Log.d("My Reciever","is intent null => " + (intent == null));
   Log.d("My Reciever",intent.getAction()+"");
   }
}
Run Code Online (Sandbox Code Playgroud)

虽然其他应用程序和服务正在接收"Screen_on"和"USer_Present"的广播,例如.WifiService.

RTS*_*lio 5

虽然Java常数android.content.intent.ACTION_USER_PRESENT,android.content.intent.ACTION_BOOT_COMPLETED以及android.content.intent.ACTION_SCREEN_ON,该这些常量的是android.intent.action.USER_PRESENT,android.intent.action.BOOT_COMPLETEDandroid.intent.action.SCREEN_ON.需要出现在清单中的是那些值.

但请注意,接收器ACTION_SCREEN_ON不能在清单中声明但必须由Java代码注册,例如请参阅此问题.