-3

First of all, apologies if this has been answered already. I've been searching for this for a couple of hours already but I wasn't able to get any answers from the web or just because I've been using the wrong keywords.

I'm currently creating an android app and I just want to know if there is a way to disable the power button when my app is running. Or in other terms, if my app is running and a person clicks on the power button, the device should not turn off or there should be a message that says "please enter passcode to exit the app" before turning off.

I'm new to android and any help is appreciated. I want to learn more if this feature exists or is possible, so if there are links that can direct me to the answer, that would suffice.

Thanks. --edit-- Just to clear things up, I'm not blocking the owner of the device to access his own device. When the app is created and activated on the device, his customers on his store can navigate through the application. I am blocking his customers from the device and not the owner of the device.

Jon
  • 29
  • 6
  • are you trying to ensure that the screen is open when the app is open then use wake lack in manifest – Aniruddha K.M Jul 09 '15 at 04:10
  • no sir, im trying to ensure that the customers (not the owner of the device) are not able to turn the device off. While the app is running, the customers should not be able to turn the device off. I know that this could be done by altering the external environment (adding some note near the device on not to turn it off, or some glass casing or something) but I just want to know if this can be done internally. – Jon Jul 09 '15 at 04:21

2 Answers2

0

This isn't possible (at least without an app that requires root, and even then I'm not sure how you would do it)

This would violate several user experience best practices. A user should always be in control of their device. If the user wants to turn the device off, it should turn off. There's a reason this isn't part of the Android SDK.

Khalos
  • 2,335
  • 1
  • 23
  • 38
  • I've also read that there could be some apps on locking but I haven't completely read on them. Thanks for your answer sir. – Jon Jul 09 '15 at 03:19
0

This is not possible.

You can check the Answer from Mark Murphy at this link.

As mentioned, unless you are using a custom Firmware, Android do not allow apps to override Power button functionality.

However, if you have custom firmware on an Android Build with CynogenMod, you may give below permission in your AndroidManifest.xml file

android.permission.PREVENT_POWER_KEY
Community
  • 1
  • 1
AADProgramming
  • 6,077
  • 11
  • 38
  • 58