Broadcast Receiver for ACTION_USER_PRESENT,ACTION_SCREEN_ON,ACTION_BOOT_COMPLETED Broadcast Receiver for ACTION_USER_PRESENT,ACTION_SCREEN_ON,ACTION_BOOT_COMPLETED xml xml

Broadcast Receiver for ACTION_USER_PRESENT,ACTION_SCREEN_ON,ACTION_BOOT_COMPLETED


Although the Java constants are android.content.intent.ACTION_USER_PRESENT, android.content.intent.ACTION_BOOT_COMPLETED, and android.content.intent.ACTION_SCREEN_ON, the values of those constants are android.intent.action.USER_PRESENT, android.intent.action.BOOT_COMPLETED, and android.intent.action.SCREEN_ON. It is those values which need to appear in your manifest.

Note, however, that a receiver for ACTION_SCREEN_ON can not be declared in a manifest but must be registered by Java code, see for example this question.


Since implicit broadcast receivers are not working as of Android 8.0, you must register your receiver by code and also in the manifest.

Do these steps:

  • Add manifest tag
<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>
  • Create a receiver class and add your codes
public class MyReciever 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()+"");   }}
  • Create a service and register the receiver in it
public class MyService extends Service {MyReceiver receiver = new MyReceiver();    @Override    public IBinder onBind(Intent intent) { return null; }    @Override    public int onStartCommand(Intent intent, int flags, int startId) {        registerReceiver(receiver);        return START_STICKY;    }    @Override    public void onDestroy() {        super.onDestroy();        unregisterReceiver(receiver);    }}
  • Don't forget to define the service in manifest
<service android:name=".MyService"/>

To make your broadcast work, you have to register it in service. And to keep your service alive you can use tools like alarm managers, jobs, etc which is not related to this question.


Check your Class name, that is extending BroadcastReceiver. It should be "MyReciever" not "MyReiever"