I'm creating an app that can detect double tap gesture from any screen. I'm able to successfully detect the double tap gesture using flagServiceHandlesDoubleTap
The issue that I'm facing is that this blocks the default touch actions and nothing happens on tapping or swiping to go back.
MyAccessibility Class
public class MyAccessibilityService extends AccessibilityService {
private static final String TAG = "MyAccessibilityService";
public static final int GLOBAL_ACTION_LOCK_SCREEN = 8;
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
}
@Override
public void onInterrupt() {
Log.e(TAG, "onInterrupt: something went wrong");
}
@Override
public boolean onGesture(@NonNull AccessibilityGestureEvent gestureEvent) {
int gestureId = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
gestureId = gestureEvent.getGestureId();
}
Log.d(TAG, "onGesture: Gesture Detected " + gestureId);
switch (gestureId){
case 17:
Log.d(TAG, "onGesture: Double Tap Happened");
}
return super.onGesture(gestureEvent);
}
}
accessibility_service_config.xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/accessibility_service_description"
android:accessibilityEventTypes="typeWindowContentChanged"
android:accessibilityFlags="flagRequestTouchExplorationMode|flagServiceHandlesDoubleTap"
android:canRetrieveWindowContent="true"
android:canRequestTouchExplorationMode="true"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"
/>
How can I handle the double tap gesture without blocking touch or default gesture actions?
You are requesting
flagRequestTouchExplorationMode. This will set the device in touch exploration mode. And any tap or swipe events are taken in account as hover events. To tap, you now have to use double tap, and to swipe you have to use double finger swipe.