0

I have the following requirement. I need to prevent not admin users exit the Android application.

So, is there any way to disable the followings

  1. long press home button event
  2. long press search button
  3. power off button press

Thanks

Squonk
  • 48,735
  • 19
  • 103
  • 135
narek.gevorgyan
  • 4,165
  • 5
  • 32
  • 52

1 Answers1

2

There is no notion of an 'admin user' in Android. You can't really do this without developing your custom Android firmware. The hardware/system buttons are controlled by the system, so you cannot disable or customize them.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • I can disable back button easily in my application . It is not a button controlled by Android system? – narek.gevorgyan May 25 '12 at 06:22
  • 1
    No you can't. You can override `onBackPressed()` in an activity, but that's it. Once you are out of the app/activity, the system will control it. And really, don't do this, it's broken in 99% of the cases. – Nikolay Elenkov May 25 '12 at 06:23
  • Even a root app can't do this? – jadkik94 May 25 '12 at 06:26
  • What is a 'root app'? If you are developing your own firmware, you can have apps with `system` permissions, but that won't change core system behaviour. On a rooted device, you can start a (separate) process with root privileges, but then what? – Nikolay Elenkov May 25 '12 at 06:28
  • @NikolayElenkov what is the problem with overriding onBackPress()? In this case user will never exit the activity with BACK button – narek.gevorgyan May 25 '12 at 06:29
  • How can you be sure of what the user wants or does not to do? By overriding it, you are changing standard system behaviour which people expect and rely on. Are you developing custom firmware or not? – Nikolay Elenkov May 25 '12 at 06:30
  • This application will load on device start-up and it is not for all users. Only customers of food delivery service will us it and not with their own devices. – narek.gevorgyan May 25 '12 at 06:33
  • 1
    OK, but overriding the back button still leaves other ways to exit and doesn't really buy you much. If you are not developing custom firmware for you device, your best bet is to create a launcher app, that can launch a single application (yours). – Nikolay Elenkov May 25 '12 at 06:36