指纹手势回调不起作用

指纹手势回调不起作用

本文介绍了Android O-指纹手势回调不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过可访问性在启用了指纹手势的像素设备上进行测试。我正在尝试使用FingerprintGestureController来获取手势回调,但是即使我从设置->可访问性打开了此应用程序的可访问性,也从未得到任何手势作为回报。 isGestureDetectionAvailable()总是向我返回false。有人可以帮忙吗?

I am testing on Pixel device with Fingerprint Gestures ON from accessibility. I am trying to get the gesture callbacks using FingerprintGestureController but never getting any gestures in return even after I turn the accessibility ON for this app from Settings->Accessibility. isGestureDetectionAvailable() is always returning false to me. Can someone please help.

这是代码:

my_gesture_service.xml

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
android:canRequestFingerprintGestures="true" />

AndroidManifest.xml

<uses-feature android:name="android.hardware.fingerprint"/>
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE"/>
<service
            android:name="android.gestures.MyService"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter>
                <action android:name="android.accessibilityservice.AccessibilityService" />
            </intent-filter>
            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/my_gesture_service" />
        </service>

MyService.java

public class MyService extends AccessibilityService {

    private static final String TAG = MyService.class.getSimpleName();

    @Override
    public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        Log.d(TAG, "onAccessibilityEvent");
    }

    @Override
    public void onInterrupt() {
        Log.d(TAG, "onInterrupt");
    }

    @Override
    protected boolean onGesture(int gestureId) {
        Log.d(TAG, "onGesture " + gestureId);
        return super.onGesture(gestureId);
    }

    @Override
    protected boolean onKeyEvent(KeyEvent event) {
        Log.d(TAG, "onKeyEvent " + event.getKeyCode());
        return super.onKeyEvent(event);
    }

    @Override
    public void onDestroy() {
        Toast.makeText(getApplicationContext(), "onDestroy" , Toast.LENGTH_SHORT).show();
        super.onDestroy();
    }



    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
        Log.d(TAG, "onServiceConnected");

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            FingerprintGestureController gestureController = getFingerprintGestureController();

            Toast.makeText(getApplicationContext(), "Is available: " + gestureController.isGestureDetectionAvailable(), Toast.LENGTH_LONG).show();
            Log.e(TAG, "Is available: " + gestureController.isGestureDetectionAvailable() );

            FingerprintGestureController.FingerprintGestureCallback callback = new
                    FingerprintGestureController.FingerprintGestureCallback() {
                        @Override
                        public void onGestureDetectionAvailabilityChanged(boolean available) {
                            super.onGestureDetectionAvailabilityChanged(available);
                            Toast.makeText(getApplicationContext(), "Gesture available change to: " + available, Toast.LENGTH_SHORT).show();
                            Log.d(TAG, "onGestureDetectionAvailabilityChanged " + available);
                        }

                        @Override
                        public void onGestureDetected(int gesture) {
                            super.onGestureDetected(gesture);
                            Toast.makeText(getApplicationContext(), "Gesture: " + gesture, Toast.LENGTH_SHORT).show();
                            Log.d(TAG, "onGestureDetected " + gesture);
                        }
                    };

            gestureController.registerFingerprintGestureCallback(callback, new Handler());
        }
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.d(TAG, "onUnbind " );
        return super.onUnbind(intent);
    }


}


推荐答案

找到了答案。我在xml中也需要这个标记:

Found the answer. I needed this one flag too in xml:

android:accessibilityFlags="flagDefault|flagRequestFingerprintGestures"

这篇关于Android O-指纹手势回调不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:06