I've got a Samsung tablet SM-T560 on which when pressing the touch 'menu' key (next to the hardware 'home' button) opens the system menu for 'Active apps' where you can close or navigate to a previously opened app.
How can i override this functionality?I want to disable showing active apps upon this menu button click.
you need to override the menu button using the onKeyDown(int, KeyEvent) method in your activity. The following code snippet should be a good start for you:
#Override
public boolean onKeyDown(int keycode, KeyEvent event) {
switch(keycode) {
case KeyEvent.KEYCODE_MENU:
//Your functionality here
return true;
}
return super.onKeyDown(keycode, event);
}
Related
I have seen many solutions to this problem, but the solutions were for older versions. Is there any way to disable the system buttons Back, Home and Menu for one activity? I am programming for android 7 and above.
You can try override onKeyDown.This can intercept back button and do something you want.Also override onBackPressed() can intercept back button.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
do something;
return true;
}
return false;
}
But the menu button and home button I'm not sure if still can intercept in now days.
You can try to lock the com.android.systemui package
i want to disable navigation bar in my app.i have use below code for it.it disable back button.now i want to disable home button when click on toggle button.how to disable home button using toggle button
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK ) {
//preventing default implementation previous to
//android.os.Build.VERSION_CODES.ECLAIR
return false;
}
return super.onKeyDown(keyCode, event);
}
You can't disable the home button.
But there is a workaround: Start your app again as soon as another app is launched.
See http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/
I am creating an Android application in my application all Activities (pages) have a Back button so by pressing I can go to previous page or another page.For going on another page I use startActivity() and finish().But when I press keyboard's Back Button it goes to page which was previously pushed in Activities Stack.And I want to synchronize Keyboard's Back button and My Activities Back button.
How can I do this Please Help..
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
//start youractivity or finish();
}
return super.onKeyDown(keyCode, event);
}
override this method on your activity
I'm working on making a game for the android, with a friend doing the artwork. My friend wants to do his own menu, as in, he made an image to be used as the menu.
My question is, is there a way to have onMenuOpened() activate upon pressing the menu button with no menu items in onCreateOptionsMenu(), and then from my SurfaceView class close the menu? Or simply, how can I do my own menu that's activated upon pressing the menu button?
You probably could use Activity onKeyDown() function and detects KeyEvent.KEYCODE_MENU and do what you want.
Your code should be something like:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// Do your own menu here
return true;
}
return false;
}
How do I have an app return to the 'Home' screen when the user is on a different class and they click the back/return button on their phone?
Right now, when they access a different class and hit the back button, it goes back to the Home screen on the Droid rather than the Home screen on the app - how do I get it to go back to the Home Screen on the app?
Thanks!
Use OnBackPressed() method of Activity class.
Make conditions like :
public void onBackPressed(){
if(conditon)
{
detailInfoList.setVisibility(View.VISIBLE);//or anything that you want to show
}
}
you can't,
the home button is the only you can't prevent form closing your app. Its done so that you can't block the user inside your applications (like a virus).
the other keys like back menu and research are possible
in your activity
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
if(keyCode == 82){
Log.i("jason","released on menu");
//change view
//return so that the other behavior (leaving the activity) is not tirggered
return false;
}
}
Log.i("jason","actual key code "+keyCode);
return super.onKeyDown(keyCode, event);
}