Question

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.

No correct solution

OTHER TIPS

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.

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.

http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html

May be this can help you for setting the passoward.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top