Monday 12 September 2011

Auto App start on Boot Completion

You can start your application when the device starts again thru BroadcastReceiver:

public class PhoneStateReceiver extends BroadcastReceiver{
   
    @Override
    public void onReceive(final Context context, Intent intent) {
       
        if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
            Intent launch = new Intent(context, ActivityToLaunch.class);
            launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(launch);
        }
    }
}


In your manifest add this:

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

Add permission:

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

No comments:

Post a Comment