how to know device is power off
I want to do something when the mobile device is closing, but 开发者_StackOverflow社区I don't know what is the method; could you tell me how to detect if mobile device is shutting down?
I know the method about mobile restartandroid.intent.action.BOOT_COMPLETED
, but I cannot find similar power off.http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN
public static final String ACTION_SHUTDOWN
Since: API Level 4 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"
This would appear to be it? I just Googled your command and it was on the Standard Broadcast Actions list. :)
精彩评论