Wednesday, 8 July 2015

How to start/ launch application at boot time Android

If you want your app to start-up automatically when Android boots up you need to the following
  
Step 1:
 add the permission android.permission.RECEIVE_BOOT_COMPLETED  to your Manifest file.
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Step 2: register receiver in your application in manifest.

        <receiver
          android:name=".YourReceiverName" <!-- name of your class that extends BroadcastReceiver -->
          android:enabled="true"          android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
          <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED" />
             <action android:name="android.intent.action.QUICKBOOT_POWERON" />
              <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
     </receiver>

     Note: this code should be inside of <application  ...> </application> of manifest file

Step 3: Create the class that extends BroadcastReceiver

public class YourReceiverName extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //Your code that has to run on start up/ boot time
    }

No comments :

Post a Comment