How to detect android phone is being turned off?

Muhammad Maqsoodur Rehman picture Muhammad Maqsoodur Rehman · Feb 18, 2014 · Viewed 12.9k times · Source

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

Answer

suresh picture suresh · Feb 18, 2014

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>