If you want your app to start-up automatically when Android boots up you need to the following
#1: add the following to your android manifest file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<receiver android:enabled="true" android:name=".BootUpReceiver" | |
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> | |
<intent-filter> | |
<action android:name="android.intent.action.BOOT_COMPLETED" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> | |
</receiver> | |
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> |
This will register for a boot complete receiver event and ask for its permission.
#2 Add a the following java class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BootUpReceiver extends BroadcastReceiver{ | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
Intent i = new Intent(context, MyActivity.class); | |
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(i); | |
} | |
} |