Booting from Android
Booting from Android can be divided into two steps:
1. Write a broadcastreceiver:
Java code
- Public class Bootreceiver extends Broadcastreceiver {
- private static final String TAG = "Bootreceiver";
- @Override
- public void OnReceive (context context, Intent Intent) {
- LOG.I (TAG, "boot auto-start");
- //Autoopenactivity is the main activity of the program
- //can also be a service running in the background
- Intent auto = new Intent (context, autoopenactivity. Class);
- Auto.addflags (Intent.flag_activity_new_task);
- Context.startactivity (auto);
- }
- }
2. Register Broadcastreceiver and add permissions in Manifest.xml:
XML code
- <receiver android:name=". Bootreceiver " >
- <intent-filter >
- <action android:name="Android.intent.action.BOOT_COMPLETED" />
- <category android:name="Android.intent.category.HOME" />
- </intent-filter>
- </receiver>
XML code
- <uses-permission android:name="Android.permission.RECEIVE_BOOT_COMPLETED" />
Booting from Android