我想使用AccessibilityService
“单击”时执行多次滑动。我已经尝试过了,但是它不执行多次滑动。任何帮助深表感谢。它正在运行,但只记录了一次滑动。
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
{
final int eventType= accessibilityEvent.getEventType();
switch (eventType)
{
case 1:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
{
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int middleYValue = displayMetrics.heightPixels / 2;
final int leftSideOfScreen = displayMetrics.widthPixels / 4;
final int rightSizeOfScreen = leftSideOfScreen * 3;
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
Path path = new Path();
if (accessibilityEvent.getText() != null && accessibilityEvent.getText().toString().contains("1"))
{
path.moveTo(rightSizeOfScreen, middleYValue);
path.lineTo(leftSideOfScreen, middleYValue);
}
else
{
path.moveTo(leftSideOfScreen, middleYValue);
path.lineTo(rightSizeOfScreen, middleYValue);
}
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
for (int i=0;i<5;++i)
{
swipe(gestureBuilder.build());
}
}
}
}
答案 0 :(得分:0)
void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
{
final int eventType= accessibilityEvent.getEventType();
switch (eventType)
{
case 1:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
{
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int middleYValue = displayMetrics.heightPixels / 2;
final int leftSideOfScreen = displayMetrics.widthPixels / 4;
final int rightSizeOfScreen = leftSideOfScreen * 3;
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
Path path = new Path();
if (accessibilityEvent.getText() != null && accessibilityEvent.getText().toString().contains("1"))
{
path.moveTo(rightSizeOfScreen, middleYValue);
path.lineTo(leftSideOfScreen, middleYValue);
}
else
{
path.moveTo(leftSideOfScreen, middleYValue);
path.lineTo(rightSizeOfScreen, middleYValue);
}
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 100, 50));
for (int i=0;i<5;++i)
{
swipe(gestureBuilder.build());
}
}
}
}