1

Can anybody share the sample code to how to launch android application upon starting/booting up the device?

Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40
piks
  • 1,621
  • 8
  • 32
  • 59

1 Answers1

1

This code will launch an application on start up. You need to listen for ACTION_BOOT_COMPLETE.

in AndroidManifest.xml (application-part):

<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" />
[..]

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);  
        }

}
Tomislav Markovski
  • 12,331
  • 7
  • 50
  • 72