Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Auto-start an Android Application?

Tags:

android

I'm not sure how to autostart an android application after the android emulator completes its booting. Does anyone have any code snippets that will help me?

like image 576
Rajapandian Avatar asked Jun 29 '09 04:06

Rajapandian


People also ask

What is Android Auto Launch?

In other words, the auto-launching support allows Android Auto users to automatically run the app every time they connect their mobile devices to the head unit in a car.

What is autostart in app?

An application called Auto Start is here to help you in autorestarting your favorite apps in one go. The application is simple to use, as it lets you pick one app that you'd like to be launched automatically as soon as your phone finishes rebooting.


1 Answers

You have to add a manifest permission entry:

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

(of course you should list all other permissions that your app uses).

Then, implement BroadcastReceiver class, it should be simple and fast executable. The best approach is to set an alarm in this receiver to wake up your service (if it's not necessary to keep it running ale the time as Prahast wrote).

public class BootUpReceiver extends BroadcastReceiver {     @Override     public void onReceive(Context context, Intent intent) {         AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);         PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context, MyService.class), PendingIntent.FLAG_UPDATE_CURRENT);         am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + interval, interval, pi);     } } 

Then, add a Receiver class to your manifest file:

<receiver android:enabled="true" android:name=".receivers.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> 
like image 64
Krzysztof Wolny Avatar answered Sep 22 '22 10:09

Krzysztof Wolny