How to disable home key: Difference between revisions
No edit summary |
|||
Line 6: | Line 6: | ||
The app declares the permission in manifest. | The app declares the permission in manifest. | ||
== | === Monitor onKeyDown === | ||
<syntaxhighlight lang="java" line='line'> | |||
//Monitor physical keyboard | |||
<syntaxhighlight lang="java"> | public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
public | |||
</syntaxhighlight > | if (keyCode == KeyEvent.KEYCODE_HOME) { | ||
=== | Log.e("DEBUG", "KEYCODE_HOME"); | ||
// android.os.Process.killProcess(android.os.Process.myPid()); | |||
btn4_home.setBackgroundColor(Color.GREEN); | |||
return true; | |||
} | |||
if (keyCode == KeyEvent.KEYCODE_BACK) { | |||
btn1_return.setBackgroundColor(Color.GREEN); | |||
Log.e(TAG, "KEYCODE_BACK"); | |||
isSuccessReturn = true; | |||
return true; | |||
} | |||
if (keyCode == KeyEvent.KEYCODE_MENU) { | |||
btn2_menu.setBackgroundColor(Color.GREEN); | |||
Log.e(TAG, "KEYCODE_MENU"); | |||
isSuccessMenu = true; | |||
return true; | |||
} | |||
return super.onKeyDown(keyCode, event); | |||
} | |||
</syntaxhighlight> | |||
=== Demo === | |||
[http://ftp.wizarpos.com/advanceSDK/DisableStatusBarOrHomeBtnInApp.zip Download demo] |
Latest revision as of 03:20, 28 April 2023
Disable home key in apk
- Defines the following permission, the third-party app will get the event of home key or back key.
- Catches the event when the home key or back key is pressed.
Permission
android.permission.CLOUDPOS_DISABLE_HOME_KEY
The app declares the permission in manifest.
Monitor onKeyDown
//Monitor physical keyboard
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
Log.e("DEBUG", "KEYCODE_HOME");
// android.os.Process.killProcess(android.os.Process.myPid());
btn4_home.setBackgroundColor(Color.GREEN);
return true;
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
btn1_return.setBackgroundColor(Color.GREEN);
Log.e(TAG, "KEYCODE_BACK");
isSuccessReturn = true;
return true;
}
if (keyCode == KeyEvent.KEYCODE_MENU) {
btn2_menu.setBackgroundColor(Color.GREEN);
Log.e(TAG, "KEYCODE_MENU");
isSuccessMenu = true;
return true;
}
return super.onKeyDown(keyCode, event);
}