I need to know when the user powers off his/her phone. Are there any broadcasts (or similar) that notify when the user’s phone is powered off?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
ACTION_SHUTDOWNIntent which is broadcast when the phone is about to shutdown. The documentation says:In other words, if you respond to all the lifecycle events for your Activity appropriately, there’s no need to use this unless you really want to do something specific related to shutdown.
The
ACTION_SHUTDOWNIntent was introduced in API Level 4, in other words it’ll only be sent on phones running Android 1.6 or later.You’ll trap the Broadcast with a
BroadcastReceiver. It will look something like this:You’ll also need an entry in your Manifest like the following:
Depending on what you’re doing, another option would be to use the
ACTION_BOOT_COMPLETEDIntent which is sent when the phone is restarted.