使用OS Marshmallow时在Android中拍摄列表活动的全屏照片。。?

使用OS Marshmallow时在Android中拍摄列表活动的全屏照片。。?,android,android-6.0-marshmallow,Android,Android 6.0 Marshmallow,如何获取包含列表视图的活动的全屏快照。我已经用比棉花糖更低的所有其他操作系统完成了。在包含棉花糖操作系统的移动设备中,它仅拍摄查看内容的屏幕截图,或在移动屏幕查看内容中。简而言之,棉花糖不允许我拍摄活动的全屏截图。我怎样才能解决这个问题? 提前谢谢。 下面是一些代码: private void pdf() { // fn_permission(); printhelper=new PrintHelper(ConversionEnergyListActivity.this);

如何获取包含列表视图的活动的全屏快照。我已经用比棉花糖更低的所有其他操作系统完成了。在包含棉花糖操作系统的移动设备中,它仅拍摄查看内容的屏幕截图,或在移动屏幕查看内容中。简而言之,棉花糖不允许我拍摄活动的全屏截图。我怎样才能解决这个问题? 提前谢谢。 下面是一些代码:

private void pdf() {
   // fn_permission();
    printhelper=new PrintHelper(ConversionEnergyListActivity.this);
    printhelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
    // image naming and path  to include sd card  appending name you choose for file
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".JPEG";
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    RelativeLayout root = (RelativeLayout) inflater.inflate(R.layout.activity_conversion_list, null); //RelativeLayout is root view of my UI(xml) file.
    root.setDrawingCacheEnabled(true);
    bitmap= getBitmapFromView(this.getWindow().findViewById(R.id.relativelayout));
    imageFile = new File(mPath);
    try{
        FileOutputStream outputStream = new FileOutputStream(imageFile);
        // Toast.makeText(ConversionEnergyListActivity.this,"Image path : "+imageFile,Toast.LENGTH_LONG).show();
        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 OOM
        e.printStackTrace();
    }
}

//create bitmap from view and returns it
private Bitmap getBitmapFromView(View view) {
    //Define a bitmap with the same size as the view
   // Bitmap returnedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
    //Bind a canvas to it
    Canvas canvas = new Canvas(returnedBitmap);
    view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);
  /*  //Get the view's background
    Drawable bgDrawable =view.getBackground();
    if (bgDrawable!=null) {
        //has background drawable, then draw it on the canvas
        bgDrawable.draw(canvas);
    }   else{
        //does not have background drawable, then draw white background on the canvas
        canvas.drawColor(Color.WHITE);
    }*/
    // draw the view on the canvas
    view.draw(canvas);
    //return the bitmap
    return returnedBitmap;
}

尝试在
pdf
方法中更改此行

bitmap= getBitmapFromView(this.getWindow().findViewById(R.id.relativelayout));
对此

bitmap = getBitmapFromView(this.getWindow().getDecorView());
并且在
getBitmapFromView
方法中:

view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);


显示一些代码如何获取当前私有位图getBitmapFromView(视图视图){Bitmap returnedBitmap=Bitmap.createBitmap(View.getWidth(),View.getHeight(),Bitmap.Config.argb8888);//将画布绑定到画布画布画布画布=新画布(returnedBitmap);View.layout(0,0,View.getLayoutParams()).width,view.getLayoutParams().height);//在画布视图上绘制视图。绘制(画布);返回返回的位图;}看起来不错,作为
视图传递给方法的是什么?显示更多代码,编辑问题,不要添加评论,它不可读…好的。我已经编辑了我的问题。
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());