I want to catch long press Back button in my Accessibility service. I use code below for it. Unluckily, something is wrong because I get log where is isLongPress = false
. My question is how to catch KeyEvent properly.
This is my service:
package com.example.android.globalactionbarservice;
import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.KeyEvent;
import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
import static android.content.ContentValues.TAG;
public class GlobalActionBarService extends AccessibilityService {
FrameLayout mLayout;
@Override
protected void onServiceConnected() {
Log.d(TAG, "MyAccessibilityService: onServiceConnected");
}
private long holdTime;
@Override
protected boolean onKeyEvent(KeyEvent event) {
Log.d(TAG, "MyAccessibilityService: onKeyEvent: action = " + event.getAction() +
"; key code = " + event.getKeyCode() +
"; scan code = " + event.getScanCode() +
"; meta state = " + event.getMetaState() +
"; key = " + event.getNumber() +
"; isLongPress = " + event.isLongPress());
return super.onKeyEvent(event);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG, "MyAccessibilityService: onAccessibilityEvent " + event.toString());
}
@Override
public void onInterrupt() {
}
}
This is the service xml:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault|flagRequestFilterKeyEvents"
android:canRetrieveWindowContent="true"
android:canRequestFilterKeyEvents="true"
android:accessibilityEventTypes="typeContextClicked|typeViewClicked"
/>
This is my log:
2019-09-09 22:02:28.690 11201-11201/com.example.android.demoservice D/ContentValues: MyAccessibilityService: onServiceConnected
2019-09-09 22:02:34.109 11201-11201/com.example.android.demoservice D/ContentValues: MyAccessibilityService: onKeyEvent: action = 0; key code = 4; scan code = 158; meta state = 0; key = ��; isLongPress = false
2019-09-09 22:02:36.345 11201-11201/com.example.android.demoservice D/ContentValues: MyAccessibilityService: onKeyEvent: action = 1; key code = 4; scan code = 158; meta state = 0; key = ��; isLongPress = false
2019-09-09 22:02:47.433 11201-11201/com.example.android.demoservice D/ContentValues: MyAccessibilityService: onAccessibilityEvent EventType: TYPE_VIEW_CLICKED; EventTime: 84040825; PackageName: com.android.settings; MovementGranularity: 0; Action: 0 [ ClassName: android.widget.Button; Text: [OK]; ContentDescription: null; ItemCount: -1; CurrentItemIndex: -1; IsEnabled: true; IsPassword: false; IsChecked: false; IsFullScreen: false; Scrollable: false; BeforeText: null; FromIndex: -1; ToIndex: -1; ScrollX: -1; ScrollY: -1; MaxScrollX: -1; MaxScrollY: -1; AddedCount: -1; RemovedCount: -1; ParcelableData: null ]; recordCount: 0
Thanks.
Controller Advice bean not instantiated at proper order in Spring Boot 2.4
What should I enter to the connection string to connect my NodeJS application to a MongoDB server?
Unable to use Computed Property Values with Dots - Unable to Set as String - JS
I am using the recommended cordova plugin as used on the ionic website to implement notifications in my app, cordova-plugin-local-notifications
I have a groovy script that run during the build which has a function that expects to File objects:
Can't run my expo project on physical device , but on virtual is workedThis is error message in expo cli: "Tunnel URL not found, falled back to LAN URL
Can anybody explain me how exactly google sign works in firebase for android? To be more specific what exactly is googleSignInOptions, googleClient object, requestIdToken() method and credentials? I am really confused!