How to start/ launch application at boot time Android

These lines of code may be helpful for you…

Step 1: Set the permission in AndroidManifest.xml

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Step 2: Add this intent filter in receiver

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

Step 3: Now you can start your application’s first activity from onReceive method of Receiver class

public class BootReceiver extends BroadcastReceiver {

   @Override
   public void onReceive(Context context, Intent intent) {
       Intent myIntent = new Intent(context, MainActivity.class);
       myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(myIntent);
   }

}

Leave a Comment

tech