android:如何通过编程获得整个屏幕的截图

ycl3bljg  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(275)

下面是截图的代码。。但问题是它只需要一个应用程序的屏幕截图。。不是整个屏幕(返回和主页按钮和通知栏)有没有任何方法,我可以采取截图为整个屏幕,而不仅仅是应用程序

private void takeScreenshot() {
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

    try {
        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";

        // create bitmap screen capture
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);

        File imageFile = new File(mPath);

        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();

      //  openScreenshot(imageFile);
    } catch (Throwable e) {
        // Several error may come out with file handling or DOM
        e.printStackTrace();
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题