美文网首页
小米利用无障碍服务快速截图(无需root)

小米利用无障碍服务快速截图(无需root)

作者: 善笃有余劫 | 来源:发表于2018-12-06 11:37 被阅读99次

    原理

    小米手机可以使用三个手指同时下滑截图
    可以使用无障碍模拟该动作快速截图
    代码如下

    代码

     public static void XiaoMiScreenCapture() {
    
            int y1 = ScreenUtils.getScreenHeight() / 2 - 400;
            int y2 = ScreenUtils.getScreenHeight() / 2 + 400;
            int x1 = 200;
            int x2 = ScreenUtils.getScreenWidth()/2;
            int x3 = ScreenUtils.getScreenWidth()-200;
            Path path1 = new Path();
            path1.moveTo(x1, y1);
            path1.lineTo(x1, y2);
            Path path2 = new Path();
            path2.moveTo(x2, y1);
            path2.lineTo(x2, y2);
            Path path3 = new Path();
            path3.moveTo(x3, y1);
            path3.lineTo(x3, y2);
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                GestureDescription.Builder builder = new GestureDescription.Builder();
                GestureDescription gestureDescription = builder
                        .addStroke(new GestureDescription.StrokeDescription(path1, 0, 1000))
                        .addStroke(new GestureDescription.StrokeDescription(path2, 0, 1000))
                        .addStroke(new GestureDescription.StrokeDescription(path3, 0, 1000))
                        .build();
                service.dispatchGesture(gestureDescription, null, null);
            }
        }
    

    使用

    调用XiaoMiScreenCapture 方法即可快速截图

    相关文章

      网友评论

          本文标题:小米利用无障碍服务快速截图(无需root)

          本文链接:https://www.haomeiwen.com/subject/qiwncqtx.html