1

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0

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.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
0

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

Steve Moretz
  • 2,758
  • 1
  • 17
  • 31
  • @EduardoRotundo I didn't exactly get what you mean.Your English is not so clear.You want to prevent the shutdown now?And by the way you can also update an answer by pressing the arrow up button. – Steve Moretz Feb 17 '19 at 15:28
  • You can cancel the power menu on a certain device with root.You also can on other devices I suppose it's simple.If you need it I can help you with that too.(But it should be rooted) – Steve Moretz Feb 17 '19 at 15:30
  • I test this option and works! so now i go to break the shutdown sequence, because now the phone goes off but the debug point it's still alive until phone off – Eduardo Rotundo Feb 17 '19 at 15:33
  • Umm,I'm not sure what you mean.So you want to cancel shutdown + process + shutdown manually? – Steve Moretz Feb 17 '19 at 15:35
  • I want trigger a process when the user press the power off option. This process can take about 20 minutes or less and after that turn off the phone – Eduardo Rotundo Feb 17 '19 at 15:37
  • Ok I get it now.Well that's gonna be so annoying for the user.But anyway.You should ask another question with a better title mentioning this process is too long.Then call me there,I'll help you with that also.Just if you upvote my answer too.That would be appreciated :) – Steve Moretz Feb 17 '19 at 15:41
  • Sorry for not used a more explict title @stevemoretz – Eduardo Rotundo Feb 17 '19 at 15:45
  • @EduardoRotundo check this topic: https://stackoverflow.com/questions/39064523/detect-power-button-long-press/39205019 – Steve Moretz Feb 17 '19 at 15:45
  • after read the post and do some tests, i see the ShutdownThread process it's not available to override or modify, because the dispatchKeyEvent only works if the activity has focus – Eduardo Rotundo Feb 17 '19 at 17:32
  • I'm not really into that,But I give you the idea all you need is to find a way to know when the power button is long pressed now I'll take it from here.You have root.So You do a shell input script to click on 0,0 and it will make the menu go away you do whatever you want now.After you're done by another shell command via root turn off the device the only part left to figure is the first part which is available in that link – Steve Moretz Feb 17 '19 at 18:32