Search code examples
androidbroadcastreceiver

How to check if my BroadcastReceiver receives the BOOT?


I have a BroadcastReceiver who should receive the BOOT.

Is there a simple way to check if the BroadcastReceiver receives the BOOT correctly?

Thanks


Solution

  • Assuming BOOT means BOOT_COMPLETED then you could use the following:

    public class BootCompleteReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
                //Do a Log or, less likely, a Toast or start your application here.
            }
        }
    };
    

    You would register this in the manifest like such:

    <receiver android:name="com.example.yourAppName.BootReceiver">
       <intent-filter>
         <action android:name="android.intent.action.BOOT_COMPLETED"/>
       </intent-filter>
    </receiver>