I am making an app exclusive for the tablet it was installed to. I wanted to put a restriction so that when the back button or home button is pressed the user will be prompted to enter a password and if the password is correct application be allowed to exit.
-
you can override onPause() method to do this – Biraj Zalavadia Feb 21 '14 at 09:26
-
4Please don't, that would be horrible UX ! – 2Dee Feb 21 '14 at 09:26
-
@2Dee the app will be exclusive to the tablet it was installed to – Christian Burgos Feb 21 '14 at 09:27
3 Answers
Overriding the back button is pretty easy, just override Activity.onBackPressed() to do whatever you want. Don't call super() or it will close the Activity!
Overriding the home button is more problematic. The only way to do so is to make your app a launcher. Then press home and select your app as the default launcher.

- 12,316
- 13
- 72
- 135
-
thanks for this.. this is a big help. yes, the home button is really problematic. if the app is made as a launcher, how do i revert to the old launcher? is that entirely possible? – Christian Burgos Feb 21 '14 at 09:46
-
1@ChristianBurgos yes, totally. Just go into the settings, application, "your-app", clear defaults. – Enrichman Feb 21 '14 at 09:48
-
how about this, if the app is the chosen default launcher then how am i gonna go the settings? – Christian Burgos Feb 21 '14 at 09:52
-
@ChristianBurgos that's why I don't think this approach will work. You should rethink the flow. One could be the one I suggested. – Enrichman Feb 21 '14 at 10:20
-
1@ChristianBurgos I know an app can programmatically deregister itself as the default launcher, but I don't know how. I know it's possible because this app does it: https://play.google.com/store/apps/details?id=com.whisperarts.kidsshell) – Barry Fruitman Feb 21 '14 at 21:46
I'm not sure that this could be a good idea. You're "blocking" the user in this way. You can probably override the back button but you will not be able to override the home button (without making the app a launcher).
I did a sort of "kiosk" application and I had the same requirements. I ended up rooting the devices and using this Hide Bar application. The user was not able to go back, and the administrator had a button to enter, with a password, into the "admin panel". In this admin panel you can push a button to go to the launcher. From there you can, with a widget included into the Hide Bar app, restore the back and home buttons.
-
1
-
@BarryFruitman you're not really overriding it. You're creating a launcher. I don't think that, pressing the home button, the user will be happy to be prompted to use "Sense" or "MyNiceBlockingApp" as new launcher. – Enrichman Feb 21 '14 at 09:39
-
the app will be exclusive to the hardware/tablet it was installed to. – Christian Burgos Feb 21 '14 at 09:44
-
1@Enrichman That's why I said he would have to do it manually the first time. – Barry Fruitman Feb 21 '14 at 20:42
http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html
May be this can help you for setting the passoward.

- 46
- 8