问题
I've an android application that will be used in a restaurant, so I want that users can't exit from the app. The only thing that users can, is using application.
(If possible only admin can exit from app, by logging in or restarting device, I don't know which is the best way).
Is there a solution or other way to do this?
Thank you very much!
回答1:
What you are looking for is a Kiosk mode app, I remember reading that on 4.2 it is possible to write home screen application that in behaviour will work like that:
http://commonsware.com/blog/2013/02/20/android-4p2-for-kiosk-apps.html
回答2:
you can override
the onBackPressed
method
@Override
public void onBackPressed(){
Toast.MakeText(getApplicationContext(),"You Are Not Allowed to Exit the App", Toast.LENGTH_SHORT).show();
}
this will prevent the back button from exiting the application.
and then you will need to override
the home button
as well like
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
Log.i("TEST", "Home Button"); // here you'll have to do something to prevent the button to go to the home screen
return true;
}
return super.onKeyDown(keyCode, event);
}
EDIT: for new devices with android version 4.0.xx you'll have to override
the recent apps button
as well
hope that helps you.
回答3:
You need a Launcher Home app: http://code.tutsplus.com/tutorials/build-a-custom-launcher-on-android--cms-21358
来源:https://stackoverflow.com/questions/15861970/android-prevent-user-from-closing-app