How to start the service when you turn on your Android device?

How to start a service when an Android device is turned on and the OS is running?

+8
android
Oct 05 '11 at 23:13
source share
1 answer

Add to AndroidManifest.xml:

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <service android:name=".YourService" /> <receiver android:name="com.your.package.AutoStart"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 

Create class AutoStart.java:

 public class AutoStart extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent startServiceIntent = new Intent(context, YourService.class); context.startService(startServiceIntent); } } 
+22
Oct 05 '11 at 23:25
source share



All Articles