How to detect android phone is being turned off? [duplicate]
Asked Answered
J

3

1

I want to do something at instant the user turns off android phone. How can my app detect it programatically?

Job answered 18/2, 2014 at 11:50 Comment(0)
C
7

http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN`

<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>
Companion answered 18/2, 2014 at 11:54 Comment(0)
L
2

This is what can provide you an insight of the OS you are working on, and not about developing an app that would run on any device, as you have not made OS's for them.

Just pull a branch of android, customize it according to your wish and in your manifest remove the filters, permissions that don't allow you to do that, or add your own. Now, you have to play with the battery if I talk of more depth.

But if you just want to trigger the click on power off then it's far simpler then.

Add in your manifest:

<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>

Now a broadcast receiver for Action SHUT DOWN will work for you.

http://developer.android.com/reference/android/content/Intent.html#ACTION_SHUTDOWN

Luganda answered 18/2, 2014 at 11:56 Comment(0)
P
0

Implement a BroadcastReceiver for ACTION_SHUTDOWN.

Pizza answered 18/2, 2014 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.