android blocks the home key inside and to disable the Home key or DIY as you wish

  • 2020-05-09 19:15:31
  • OfStack

You can disable the Home key, then process the key values in onKeyDown, click and then close the program when you hit the Home key, or DIY as you like.
 
@Override 
public boolean onKeyDown(int keyCode, KeyEvent event){ 
if(KeyEvent.KEYCODE_HOME==keyCode) 
android.os.Process.killProcess(android.os.Process.myPid()); 
return super.onKeyDown(keyCode, event); 
} 
@Override 
public void onAttachedToWindow(){ 
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); 
super.onAttachedToWindow(); 
} 

Add permissions to disable the Home key

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission> 

Related articles: