Android Accessibility 模拟界面滑动

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);

 

你可能感兴趣的:(Android Accessibility 模拟界面滑动)