handling phone shutdown event in android

后端 未结 3 830
再見小時候
再見小時候 2020-12-03 03:04

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 detec

相关标签:
3条回答
  • 2020-12-03 03:52

    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

    0 讨论(0)
  • 2020-12-03 03:53

    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

    0 讨论(0)
  • 2020-12-03 03:58
    <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>
    
    0 讨论(0)
提交回复
热议问题