isGestureDetectionAvailable 在 Android 10 上返回 false

问题描述

isGestureDetectionAvailable() 总是返回 false。我在 SO 上查看了这个问题,过去几年中所有遇到同样问题的人都没有得到答案或得到解决。 HereHere 以及其他任何地方。正确答案将获得50分奖励作为感谢。

AndroidManifest.xml

<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />


  <service
        android:enabled="true"
        android:name="helpers.FingerprintSVC"
        android:label="@string/app_name"
        android:accessibilityFlags="flagDefault|flagRequestFingerprintGestures"
        android:canRequestFingerprintGestures="true"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibility_service_config" />
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>
  </service>

指纹SVC

public class FingerprintSVC extends AccessibilityService {

private static final String TAG = "++++";

@Override
public int onStartCommand(Intent aIntent,int aFlags,int aStartId){
    super.onStartCommand(aIntent,aFlags,aStartId);

    Log.d(TAG,"onStartCommand");

    if(!isAccessibilityServiceEnabled(this,this.getClass())){
        Toast toast= Toast.makeText(this,"Enable A.SVC",Toast.LENGTH_LONG);
        toast.setGravity(Gravity.TOP|Gravity.FILL_HORIZONTAL,0);
        toast.show();

        Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    return START_STICKY;
}

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

@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,"onGestureDetected " + gesture);
                    }
                };

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

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


public boolean isAccessibilityServiceEnabled(Context context,Class<?> accessibilityService) {
    ComponentName expectedComponentName = new ComponentName(context,accessibilityService);

    String enabledServicesSetting = Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
    if (enabledServicesSetting == null)
        return false;

    TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':');
    colonSplitter.setString(enabledServicesSetting);

    while (colonSplitter.hasNext()) {
        String componentNameString = colonSplitter.next();
        ComponentName enabledService = ComponentName.unflattenFromString(componentNameString);

        if (enabledService != null && enabledService.equals(expectedComponentName))
            return true;
    }

    return false;
}

}

build.gradle

android {
compileSdkVersion 30
buildToolsVersion '29.0.3'
defaultConfig {
    applicationId "com.xxxx.xxxx"
    minSdkVersion 26
    targetSdkVersion 30
}

我正在由 Android 10 驱动的三星 M11 上进行测试。我没有其他设备可供测试。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...