禁用Android主页按钮

时间:2016-04-28 11:39:20

标签: android android-studio lockscreen

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

我在Samsung Note 3和xiaomi redmi 1中测试。

Note 3中的所有物理按钮都已锁定,但不知何故我无法禁用xiaomi redmi 1的主页按钮。 **主页按钮将在暂停事件中运行。

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);
}

2 个答案:

答案 0 :(得分: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.

答案 1 :(得分: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> 
相关问题