1

I have been developing some Android application and I need to catch some events: when the device is rebooting and when device is shutting down. I know which BroadcastReceiver I should use for the first task but I don't know anything the second one. Please, tell me about it. Thank you.

user1166635
  • 2,741
  • 6
  • 22
  • 32
  • possible duplicate of [Is there any way to get a notice when a user power off their Android phone?](http://stackoverflow.com/questions/2190126/is-there-any-way-to-get-a-notice-when-a-user-power-off-their-android-phone) – eldarerathis May 30 '12 at 18:13

1 Answers1

2

You can ACTION_SHUTDOWN Intent which is broadcast when the phone is going shutdown. Register ACTION_SHUTDOWN intent-filter action in Manifest as:

<receiver android:name=".myReceiver">
  <intent-filter>
    <action android:name="android.intent.action.ACTION_SHUTDOWN" />
  </intent-filter>
</receiver>

and in your java code:

public class myReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.intent.action.ACTION_SHUTDOWN")){
            //DO SOMETHING HERE
         }
        else
         {
                ...
         }
    }

}
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213