美文网首页
Android工具の免root屏幕截图

Android工具の免root屏幕截图

作者: 阿狸_小乖 | 来源:发表于2018-01-11 19:34 被阅读0次
    private void screenshot() {
            // 获取屏幕
            View dView = getWindow().getDecorView();
            dView.setDrawingCacheEnabled(true);
            dView.buildDrawingCache();
            Bitmap bmp = dView.getDrawingCache();
            if (bmp != null) {
                try {
                    // 获取内置SD卡路径
                    String sdCardPath = Environment.getExternalStorageDirectory().getPath();     // 图片文件路径
                    String filePath = sdCardPath + File.separator + "screenshot.png";
                    File file = new File(filePath);
                    FileOutputStream os = new FileOutputStream(file);
                    bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
                    os.flush();
                    os.close();
                } catch (Exception e) {
    
                }
            }
        }
    

    使用方法:

    screenshot();
    

    说明:
    本方法不能显示状态栏图标,但是可以截图状态栏


    image.png

    相关文章

      网友评论

          本文标题:Android工具の免root屏幕截图

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