分享

Root后安卓截屏代码...

 创始元灵6666 2022-09-10 发布于河北

安卓截屏代码有许多方式,看了几个感觉有些复杂,有的用view的getCache方法,不知道能不截屏非当前view界面的图片,有些还要修改mk文件之类的,很是头大。

此处介绍一种简易的方式。需要手机已经root。第一次调用时会弹出对话框询问是否同意其使用权限。

代码如下:

    /**
     * take snapshot. need phone to be rooted
     * @param strPath  the pic path to save
     * @return         the real pic path
     * @throws IOException
     * @throws InterruptedException
     */
    public static String takeSnapShoot(String strPath) throws IOException, InterruptedException {
        if (strPath.isEmpty()){
            strPath=String.format("/sdcard/%s.png",getCurTimeStr());
        }
        Process sh = Runtime.getRuntime().exec("su", null,null);
        OutputStream os = sh.getOutputStream();
        os.write(("/system/bin/screencap -p " + strPath).getBytes("ASCII"));
        os.flush();
        os.close();
        sh.waitFor();
        return strPath;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

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

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多