0

I have the following code to listen to any Broadcast event related to any Android shutdown event. Can I abort the shutdown event (or have it wait), and kick off an Activity. Only shutdown after when that Activity is completed. If not, any workaround for this?

Thanks

AndroidManifest.xml

<receiver android:name=".ShutdownReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
        <action android:name="android.intent.action.ACTION_SHUTDOWN" />
    </intent-filter>
</receiver>

ShutdownReceiver.java

public class ShutdownReceiver extends BroadcastReceiver {
    public static final String TAG = MainActivity.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Shutdown!");
        // Abort the Shutdown signal
        // Starts an Activity and wait until the Activity is completed before shutdown
    }   
}
samxiao
  • 2,587
  • 5
  • 38
  • 59
  • 1
    I'm pretty sure you can't do this without a rooted device and even then I'm not sure. You would need to save whatever data you need when this event is fired. What exactly are your intentions/needs? We may be able to help with a better sollution – codeMagic May 30 '13 at 00:33
  • I want to write something to put the password when someone tries to shutdown the device, to prevent from getting stolen. Basically enforce a security on shutdown. In a case of a rooted device, how do we do it then? – samxiao May 30 '13 at 00:41
  • So they have to enter a password to shutdown the device, correct? Yes, it would have to be rooted and sorry I don't know the answer to that – codeMagic May 30 '13 at 00:44
  • @xbeta If I came across such a security measure and really needed the phone to be off, I'd pop out the battery, or in case of a non-removable battery (eg Nexus 4), I'd down the power button for a few secs and force a power off. Back on topic, the shut down broadcast is just that - if you somehow receive it, there won't be much you can do. – A--C May 30 '13 at 00:56
  • @A--C, can we capture long-press power button then? – samxiao May 30 '13 at 00:57
  • 1
    @xbeta Maybe [this](http://stackoverflow.com/questions/3703071/how-to-hook-into-the-power-button-in-android) is of help. Either way, my point stands - turning off a phone (note, different than "shutting down" is extremely easy). – A--C May 30 '13 at 01:00
  • @A--C thanks for the link, but that won't help me because that required an Activity running/active. In most cases, the Activity is paused/stopped, and shutting down that way won't help. – samxiao May 30 '13 at 04:32

0 Answers0