0

I'm implementing lock screen apps, user required to key in passcode and unlock the device for some duration.

I test in Samsung Note 3 and xiaomi redmi 1.

All the physical buttons in Note 3 has been locked, but somehow I cannot disable xiaomi redmi 1's home button. **The home button will run onPause event.

enter image description here

I used the code couldn't show the button in logcat.

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

I've try to use onPause and run my apps again, but it respond slow.

@Override
public void onPause() {
    super.onPause();.
    Intent intent = new Intent(LockScreenActivity.this, SettingActivity.class);
    startActivity(intent);
}
Jasper Jye
  • 81
  • 6

2 Answers2

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.
techniqez
  • 135
  • 1
  • 9
  • I already have the code in my app, still cannot disable the home button in xiaomi redmi note1, maybe the button is special... – Jasper Jye Apr 28 '16 at 12:17
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> 
Jay Chen
  • 11
  • 1