I am developing lock application. I have to make the Home Button passive. I wrote an accessbility service.The Samsung j7 prime also works but does not work on phones in home button. I tried classic methods but it is not. Please help.
My Accessbility Service
public class LockWindowAccessibilityService extends AccessibilityService {
@Override
protected boolean onKeyEvent(KeyEvent event) {
LockScreen.getInstance().init(this);
Log.i("#### KEY_CODE ####", String.valueOf(event.getKeyCode()));
if (((LockApplication) getApplication()).lockScreenShow) {
// disable home
if (event.getKeyCode() == KeyEvent.KEYCODE_HOME || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode() == KeyEvent.KEYCODE_APP_SWITCH) {
return true;
}
}
return super.onKeyEvent(event);
}
@Override
protected boolean onGesture(int gestureId) {
if(gestureId == GLOBAL_ACTION_HOME) {
Log.d(TAG, "Gesture Home Pressed");
}
return super.onGesture(gestureId);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
Log.d("onAccessibilityEvent","onAccessibilityEvent");
/*
final int eventType = accessibilityEvent.getEventType();
switch (eventType) {
case AccessibilityEvent.TYPE_VIEW_CLICKED:
break;
case AccessibilityEvent.TYPE_VIEW_FOCUSED:
break;
}
*/
}
@Override
public void onInterrupt() {
}
}
My Accessbility.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/permission_accessibility_setting_description"
android:accessibilityEventTypes="typeAllMask"
android:packageNames="com.abc"
android:accessibilityFlags="flagRequestFilterKeyEvents|flagIncludeNotImportantViews|flagReportViewIds"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="1000"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true" />