分享

Android...

 创始元灵6666 2022-09-21 发布于河北
public class Util { /** * 模拟屏幕点击事件,点击坐标(x,y) * * @param x * @param y */ public static int[] click(int x, int y) { int[] xy = {x, y}; InputStream is = null; ByteArrayOutputStream baos = null; List<String> commands = new ArrayList<String>(); commands.add("input"); commands.add("tap"); commands.add("" + x); commands.add("" + y); ProcessBuilder pb = new ProcessBuilder(commands); try { Process prs = pb.start(); is = prs.getInputStream(); byte[] b = new byte[1024]; int size = 0; baos = new ByteArrayOutputStream(); while ((size = is.read(b)) != -1) { baos.write(b, 0, size); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); if (baos != null) baos.close(); } catch (Exception ex) { } } return xy; } /** * 模拟屏幕滑动事件,从(x,y)滑动到(newX,newY) * * @param x * @param y * @param newX * @param newY */ public static void slide(int x, int y, int newX, int newY) { InputStream is = null; ByteArrayOutputStream baos = null; List<String> commands = new ArrayList<String>(); commands.add("input"); commands.add("swip"); commands.add("" + x); commands.add("" + y); commands.add("" + newX); commands.add("" + newY); ProcessBuilder pb = new ProcessBuilder(commands); try { Process prs = pb.start(); is = prs.getInputStream(); byte[] b = new byte[1024]; int size = 0; baos = new ByteArrayOutputStream(); while ((size = is.read(b)) != -1) { baos.write(b, 0, size); } } catch (IOException e) { e.printStackTrace(); Log.d("Sim", "slide: " + e.getMessage()); } finally { try { if (is != null) is.close(); if (baos != null) baos.close(); } catch (Exception ex) { Log.d("Sim", "slide: " + ex.getMessage()); } } } }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多