How to perform multiple swipe using AccessibilityService

白昼怎懂夜的黑 提交于 2021-02-11 14:56:31

问题


I want to perform multiple swipe when "Clicked" using AccessibilityService. I already tried this but it doesn't perform multiple swipe. Any help is much appreciated. It is working but only one swipe is registered.

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

回答1:


http://jatimqq.winpublic

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


来源:https://stackoverflow.com/questions/53356373/how-to-perform-multiple-swipe-using-accessibilityservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!