80,349
社区成员
发帖
与我相关
我的任务
分享
fun click(x: Int, y: Int) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return
val path = Path()
path.moveTo(x.toFloat(), y.toFloat())
val builder = GestureDescription.Builder()
val gestureDescription = builder
.addStroke(GestureDescription.StrokeDescription(path, 50, 200))
.build()
val result = dispatchGesture(gestureDescription, @RequiresApi(Build.VERSION_CODES.N)
object : GestureResultCallback() {
override fun onCancelled(gestureDescription: GestureDescription?) {
super.onCancelled(gestureDescription)
Timber.i("onCancelled : gestureDescription")
}
override fun onCompleted(gestureDescription: GestureDescription?) {
super.onCompleted(gestureDescription)
Timber.i("onCompleted : gestureDescription")
}
}, null)
Timber.i("dispatch gesture: $result, x = $x, y = $y")
}
检查无障碍服务的xml清单文件中,有没有打开 允许 接受模拟触摸的选项:android:canPerformGestures="true"