Guest Sami Beck Posted August 8, 2011 Report Posted August 8, 2011 Is this possible to autolaunch apps/widgets on boot on a custom rom?
Guest t0mm13b Posted August 9, 2011 Report Posted August 9, 2011 Yes it is. There's a broadcast message that is sent upon boot up called ACTION_BOOT_COMPLETED. A broadcast receiver is rigged up in place to "listen" for the intent message. public class MyAppBoot extends BroadcastReceiver{ private static final String TAG = "MyAppBoot"; @Override public void onReceive(Context context, Intent intent) { if (intent != null && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){ AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(context, MyAppBootAlarm.class); PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0); mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+45, pi); } } } Once the message is received, best practice dictates that you set a timer after the boot message is processed, in order to give the system a chance to "settle" down, in the above example, a broadcast for the alarm will trigger in 45 seconds. It is considered bad practice to hog up the boot process. Once the alarm gets fired it will trigger a broadcast message similar to the above sample and from there, spin up the app. There is such an app - if you look in the market for Auto run or auto start But be careful not to hog up your handset when booting - which would slow it down and lead you to thinking that something is wrong.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now