最常见的答案是您需要添加 android:canPerformGestures="true",但我已经添加了它。请帮助我理解这一点。我正在用 flutter 编写一个程序,我试图通过创建的插件做出手势。 授予权限并调用 onServiceConnected 函数。 手势代码:
fun clickAt(x: Int, y: Int): Boolean {
val gestureBuilder = GestureDescription.Builder()
val path = Path()
path.moveTo(x.toFloat(), y.toFloat())
gestureBuilder.addStroke(GestureDescription.StrokeDescription(path, 0, 1L))
val gesture: GestureDescription = gestureBuilder.build()
return dispatchGesture(gesture, object : GestureResultCallback() {
override fun onCompleted(gestureDescription: GestureDescription) {
Log.d("start", "+++++");
super.onCompleted(gestureDescription)
}
override fun onCancelled(gestureDescription: GestureDescription) {
Log.d("start", "-----");
super.onCancelled(gestureDescription)
}
}, null)
}
代码已添加到清单中:
<service
android:name="com.example.macroexternal.macrodroid.accessibility_plugin.TextReaderAccessibilityService"
android:exported="false"
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/accessibilityservice" />
</service>
代码添加到单独的 xml 文件accessibilityservice:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:canPerformGestures="true"
android:accessibilityEventTypes="typeWindowsChanged|typeAllMask|typeWindowStateChanged|typeWindowContentChanged"
android:notificationTimeout="300"
android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews|flagRequestEnhancedWebAccessibility|flagReportViewIds"
android:canRetrieveWindowContent="true"
android:settingsActivity="com.example.macroexternal.SettingsActivity"
android:canRequestTouchExplorationMode="true"
>
</accessibility-service>
我不知道我错过了什么。 dispatchGesture 总是返回 false 并且 onCompleted 和 onCancelled 函数不会被调用
我尝试阅读文档并询问 GPT,但找不到任何其他内容。
正如我所想,答案很简单。因为我是android开发新手。我正在创建自己的 AccessibilityService 类实例,而应用程序将其本身创建为服务。根据你的班级。而且你需要学会和他沟通。