I'm looking for a way to listen for a device being powered off in android, but I don't want to include device restarts. I found Intent.ACTION_SHUTDOWN which looked useful but that includes reboots, since the device is technically powered off then back on. Is there a way to take action when a device is powered off but not when it's restarted?
Asked
Active
Viewed 740 times
0
-
Take a look at [this post](https://stackoverflow.com/questions/2190126/is-there-any-way-to-receive-a-notification-when-the-user-powers-off-the-device) - why don't you listen for ACTION_BOOT_COMPLETED as well so you can exclude reboots? – Bö macht Blau Aug 13 '18 at 19:25
-
My concern is that ACTION_BOOT_COMPLETED occurs on every power on, whether restart or turning a phone on from being off, and I don't have a way to listen for both events. Also, the shutdown event happens before the phone powers off and boot_completed happens when it turns back on so I'd have to watch for the two events to happen within a certain time period and assume the device restarted which just seems like bad practice. Any other ideas? – Caitlyn Wiley Aug 14 '18 at 20:05