Home Tags Archive
+ TWITTER Add to Google
Resources
Recent Articles

Android Boot Receiver

Authors : luigi agosti - Date : 01/11/2010 - Views : 7363
android boot receiver
Sometimes is useful to be able to intercept reboot events.

For example of you have to set up a service that run at different intervals using the AlarmManager You have to make sure to handle the reboot and reset the alarm because is lost otherwise.

So if you need to listen to reboot events in Android there is a simple way:

1. Add permission to RECEIVE_BOOT_COMPLETED
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2. Add a receiver in the AndroidManifest.xml
<receiver android:name=".receiver.BootReceiver">
    <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>
3. Implement a receiver and do implements the necessary method.
public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
       //TODO   
    }
}
Related