简体   繁体   中英

Is it possible to override the power off action?

I'm trying to modify or override the functionality of power off menu button in android (not the button to screen on / off).

I want to fired a process before the device shutdown, run a process and after that shutdown the device

If this it's possible?

Simple answer: No .

This is not possible, without custom modification to your firmware or the core of the Android operating system, for a limited number of devices. More info

So on a rooted device, you might be able to do that. Check this link.

Yes it is possible.You don't have to have a rooted device just use a broadcast. In manifest:

<receiver android:name="com.example.broadcastreceiver.YourClass">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_SHUTDOWN" />
    </intent-filter>
</receiver>

YourClass:

public class YourClass extends BroadcastReceiver {
    @Override
    public void onReceive(Context c, Intent i) {
          if(i.getAction().equals("android.intent.action.ACTION_SHUTDOWN")){
                     //Fire your code here      
          }
    }};
}

If it sounds impossible,Find another way to do the same thing ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM