accessbility service 实现点击

点击代码:

 /**
     * 坐标模拟点击:最低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://www.kkview.com

https://blog.csdn.net/wxz1179503422/article/details/105114129

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值