点击代码:
/**
* 坐标模拟点击:最低api24,即要求Android7.0以上
*/
fun click(accessibilityService: AccessibilityService, x: Float, y: Float) {
val builder = GestureDescription.Builder()
val path = Path()
path.moveTo(x, y)
path.lineTo(x, y)
builder.addStroke(GestureDescription.StrokeDescription(path, 0, 1))
val gesture = builder.build()
accessibilityService.dispatchGesture(
gesture,
object : AccessibilityService.GestureResultCallback() {
override fun onCancelled(gestureDescription: GestureDescription) {
super.onCancelled(gestureDescription)
}
override fun onCompleted(gestureDescription: GestureDescription) {
super.onCompleted(gestureDescription)
}
},
null
)
}
参考:
https://blog.csdn.net/Ikulm/article/details/126390965
Android Accessibility 模拟界面滑动1
1 Accessibility配置请查看https://blog.csdn.net/qq_27885521/article/details/102910188
2 绘制path
Path mPath = new Path();//线性的path代表手势路径,点代表按下,封闭的没用
//x y坐标 下面例子是往下滑动界面
mPath.moveTo(100,200);//代表从哪个点开始滑动
mPath.lineTo(100,100);//滑动到哪个点
3 模拟绘制手势
MainService.mainService.dispatchGesture(new GestureDescription.Builder().addStroke(new GestureDescription.StrokeDescription
(mPath, 20, 500)).build(), new AccessibilityService.GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
super.onCompleted(gestureDescription);
Toast.makeText(TransparentActivity.this, "模拟手势成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(GestureDescription gestureDescription) {
super.onCancelled(gestureDescription);
Toast.makeText(TransparentActivity.this, "模拟手势失败",Toast.LENGTH_SHORT).show();
}
}, null);
原文链接:https://blog.csdn.net/qq_27885521/article/details/103388806
最全的接收类型列表:
AccessibilityEventTypes 此服务希望接收的事件类型
https://blog.csdn.net/wxz1179503422/article/details/105114129