2016-04-28 150 views
0

我正在实施锁屏应用,用户需要输入密码并在一段时间内解锁设备。禁用Android主页按钮

我在三星Note 3和小米红米手机1.

所有注3物理按键已被锁定测试,但不知何故,我不能禁用小蜜红米手机1的home键。 **主页按钮将运行onPause事件。

enter image description here

我使用的代码无法显示logcat中的按钮。

@Override 
    public boolean dispatchKeyEvent(KeyEvent event) { 
     Log.d("button", String.valueOf(event.getKeyCode())); 
     return true; 
    } 

我尝试使用onPause并再次运行我的应用程序,但它响应缓慢。

@Override 
public void onPause() { 
    super.onPause();. 
    Intent intent = new Intent(LockScreenActivity.this, SettingActivity.class); 
    startActivity(intent); 
} 
+0

[如何禁用home键(http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key) –

+0

检查可能的复制这个http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key –

回答

1
Try this overridden method 

@Override 
public void onAttachedToWindow() { 
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); 
    super.onAttachedToWindow(); 
} 


but it's not a good practice to disable home button. 
+0

我已经在我的应用程序中的代码,仍然不能禁用xiaomi redmi note1中的主页按钮,也许该按钮是特殊的... –

1
change laucher 
modify AndroidManifest.xml 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

To: 
-------------------------------------- 
     <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.HOME"/> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.MONKEY" /> 
     </intent-filter>