-2

I stuck in little tricky logic. I want to prevent my device to turn off when my device is locked. I am just making an app for antitheft but here is problem that my logic is not working in Pie devices.

That's means after lots of searching on stack overflow. and try lots of code I am still unable to detect of my power key. I tried KEYCODE EVENT but it was use less.

After lots of try from two months Now I am forget that How many answered I have been tried.

Hope fully all of you guys will help me to solve my problem.

Main Problem

How can I prevent my device to turn off when my device is locked. (Specially Pie Devices and above)

You can consider my problem as

I want to disable my device my Power button Long press function when my device is locked

You can also consider my problem as

Override on Power button when my device is locked

BlackBlind
  • 772
  • 9
  • 26
  • 1
    Your device powers off when it's locked? I've never seen this behaviour before – PPartisan Jun 07 '19 at 14:06
  • 2
    @PPartisan I think he's saying he wants to prevent someone from turning off the device when it is locked via holding the power button down. He said it's an anti-theft feature so I assume he wants the phone powered on when stolen so it can be located with gps. Just guessing, the question isnt that clear to me either – GregH Jun 07 '19 at 14:08
  • @GregH You are clearly getting my point . – BlackBlind Jun 07 '19 at 14:09
  • @PPartisan you can read the logic of `Gregh` He is clearly getting my point. – BlackBlind Jun 07 '19 at 14:10
  • @ReazMurshed I am very clearly with my words. Here turning off means switch off. – BlackBlind Jun 07 '19 at 14:13
  • @BlackBlind im not sure if this is feasible any way as there's no way to prevent devices from turning off if someone removes the battery. Is that not a concern of yours? – GregH Jun 07 '19 at 14:25
  • @GregH but it will be concern in that device which have inbuild battery. and other word I want to disable power button long press function when device is locked. – BlackBlind Jun 07 '19 at 14:30
  • doesn't look like it's possible to prevent a reset via long-holding the power button as it's a hardware handled operation, not software (without rooting the devices or doing other things that 99.9% of users aren't willing to do). see https://android.stackexchange.com/questions/65246/how-to-prevent-someone-from-powering-off-an-android-device – GregH Jun 07 '19 at 14:36
  • 1
    You mean to say you've built an application that can prevent a user from powering off their device by long-pressing the hardware power button, and this works on pre-Android 9 devices? I wouldn't have thought that possible – PPartisan Jun 07 '19 at 14:36
  • @PPartisan Bro it is possible because few time ago I have an app which will prevent to turn of my device when my phone is locked. But that app not working in Pie device. – BlackBlind Jun 07 '19 at 14:54
  • @GregH see my latest comment and which app was I had it was work without rooted device. – BlackBlind Jun 07 '19 at 14:54
  • 1
    Didn't try this but with overlay permission you can create a full black window appear over the shutdown activity, which will look like power button is not working at all in an amoled display.But as @GregH said you cannot disable long press reboot without root. – Onur Jun 10 '19 at 07:11
  • @Onur can I override my power button – BlackBlind Jun 10 '19 at 07:23
  • @Onur as I told I had that which worked like that but unfortunately does not working in pie. – BlackBlind Jun 10 '19 at 07:24

1 Answers1

0

Right now, in your situation, YouTube is going to be your best buddy.

You don't give any information on what programming language you are using and what type of device you are targetting (Android, IOS, Windows, etc.) So it is a bit tricky to try and answer your question.

If you are trying to use a KeyCode method to grab the power button, then I would first look up what the key code for the power button is (on your specific device model) and then trying to program a KeyDown() event to try and read the KeyCode.

If you would like a more specific answer to your solution, I suggest giving us a bit more information about your problem, such as the Operating System (Android, IOS), What IDE you are using(Xcode, NetBeans, Android Studio), what model is your phone(A specific iPhone or Android model) and a bit more information as to what you HAVE tried to fix your issue

Plaguedriver
  • 75
  • 1
  • 14
  • First I am specially mentioned I want code or logic for specially Pie devices means `Android Pie`. and if you want to do know about IDE so that is `Android Studio` and for model I am clearly mention that I am making a app for antithieft so It is for all that means I want run code for all devices. But for You Can give me a suggestion for specific `NOKIA 6.1 plus` – BlackBlind Jun 13 '19 at 06:29
  • 1
    Ok, sorry for not realizing that you did specify what you are using. I think I may have found an answer to your question though. Have you looked at this link -> https://stackoverflow.com/questions/3703071/how-to-hook-into-the-power-button-in-android because it looks like it explains what you are looking to do. If you have already gotten this far then please let me know. – Plaguedriver Jun 13 '19 at 16:45
  • I have been tried that answer but it is not working. May be I am doing mistake somewhere. Did you try this ? Or can you try for me . – BlackBlind Jun 14 '19 at 07:51