How to disable home key: Difference between revisions

From wizarPOS
No edit summary
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Disable home key in apk ==
== Disable home key in apk ==
* Define the follow permission, after the permission defined, the app will get the event of home key or back key.
* Defines the following permission, the third-party app will get the event of home key or back key.
* catch the event when the home key or back key has been pressed.
* Catches the event when the home key or back key is pressed.
=== Permission ===
=== Permission ===
   android.permission.CLOUDPOS_DISABLE_HOME_KEY
   android.permission.CLOUDPOS_DISABLE_HOME_KEY
The app declare the permission in manifest.
The app declares the permission in manifest.


== Disable home key in activity ==
=== Monitor onKeyDown ===
Define the follow permission, after the permission defined, then set the activity window type is TYPE_KEYGUARD or TYPE_KEYGUARD_DIALOG, will catch the event when the home key or back key has been pressed. For example:
<syntaxhighlight lang="java" line='line'>
<syntaxhighlight lang="java">
//Monitor physical keyboard
public void onAttachedToWindow() {                                     
    public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onAttachedToWindow();                                         
try {                                                                
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
} catch (Throwable e) {                                             
e.printStackTrace();                                               
}                                                                   
}                                                                     


</syntaxhighlight >
        if (keyCode == KeyEvent.KEYCODE_HOME) {
=== Permission ===
            Log.e("DEBUG", "KEYCODE_HOME");
  android.permission.CLOUDPOS_DISABLE_HOME_KEY_IN_ACTIVITY
// android.os.Process.killProcess(android.os.Process.myPid());
The app declare the permission in manifest.
            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);
    }

Demo

Download demo