单击我的按钮时,如何共享我的屏幕投影



我写了这样的代码:当点击我的共享按钮时,是的,我的屏幕照片保存到sd卡,但当ı在facebook或蓝牙上按下共享时,它说找不到。如果我手动选择照片,我可以共享,但ı想在点击共享按钮时共享我的屏幕图片?如何做到这一点?

mylayout.setDrawingCacheEnabled(true);


// this is the important code :)
// Without it the view will have a
// dimension of 0,0 and the bitmap will
// be null


mylayout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
mylayout.layout(0, 0, mylayout.getWidth(), mylayout.getHeight());
mylayout.buildDrawingCache(true);
Bitmap bm = Bitmap.createBitmap(mylayout.getDrawingCache());
mylayout.setDrawingCacheEnabled(false); //


if (bm != null) {
    try {
        String  path2 = Environment.getExternalStorageDirectory().toString();
        OutputStream fOut = null;
        File file = new File(path2, "screentest.jpg");
        pathim=file.getPath();
        fOut = new FileOutputStream(file);


        bm.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
        fOut.flush();
        fOut.close();


        Log.e("ImagePath", "Image Path : "
                + MediaStore.Images.Media.insertImage(
                        getContentResolver(), file.getAbsolutePath(),
                        file.getName(), file.getName()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
Uri screenshotUri = Uri.parse(pathim);

sharingIntent.setType("image/jpg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "share with"));

尝试更改此行:

Uri screenshotUri = Uri.parse(pathim);

进入:

Uri screenshotUri = Uri.fromFile(file);

并将File file声明移动到if() 外部

相关内容

  • 没有找到相关文章

最新更新