Is It Possible To Launch An Android Application Activity When The Phone Starts?
Im attempting to build an android application and one of the key features to this application is for it to be able to launch an activity automatically when the phone starts, I see
Solution 1:
You need to implement BroadCastreceiver like this:
publicclassPhoneStateReceiverextendsBroadcastReceiver{
@OverridepublicvoidonReceive(final Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intentlaunch=newIntent(context, AcitivityToLaunch.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
}
}
}
In your manifest add this:
<receiverandroid:name=".receiver.PhoneStateReceiver"><intent-filter><actionandroid:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver>
Add permission:
<uses-permissionandroid:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Post a Comment for "Is It Possible To Launch An Android Application Activity When The Phone Starts?"