Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handling phone shutdown event in android

Could you post a simple code to handle shutdown event. I need manifest and receiver.

I need the following: I have a service running in background and I want to detect phone shutting down in order to make it in silent mode so that the terrible operator music doesn't play.

After restarting the phone (I already have on boot receiver) the service will enable phone sound.

like image 692
Ton Avatar asked May 04 '12 11:05

Ton


3 Answers

You need to listen for the following intent action in your receiver:

<action android:name="android.intent.action.ACTION_SHUTDOWN" />

To make it compatible with some HTC (or other) devices which offer quick power-off feature, you need to include the following action too with in the same intent-filter:

<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />

For more info, read this

like image 198
waqaslam Avatar answered Nov 11 '22 03:11

waqaslam


<receiver android:name=".ShutdownReceiver">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        <action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
    </intent-filter>
</receiver>
like image 12
Vishesh Chandra Avatar answered Nov 11 '22 01:11

Vishesh Chandra


public static final String ACTION_SHUTDOWN

Broadcast Action: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping). Once the broadcast is complete, the final shutdown will proceed and all unsaved data lost. Apps will not normally need to handle this, since the foreground activity will be paused as well.

This is a protected intent that can only be sent by the system.

Constant Value: "android.intent.action.ACTION_SHUTDOWN"

And this ACTION_SHUTDOWN may differ from device to device

Like HTC its android.intent.action.QUICKBOOT_POWEROFF

like image 2
Som Avatar answered Nov 11 '22 01:11

Som