BootReceiver.java
public class BootReceiver extends BroadcastReceiver { public void onReceive(Context ctx, Intent intent) { Log.d("BootReceiver", "system boot completed"); // start service Intent s = new Intent(ctx, ServiceName.class); ctx.startService(s); }
}
AndroidManifest.xml
<service android:name=".ServiceName"> <intent-filter> <action android:name="android.intent.action._SERVICE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service>
<receiver android:name=".BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.actegory.HOME" /> </intent-filter> </receiver>