1

我写了这段代码:当点击我的分享按钮时,是的,我的屏幕照片保存到 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"));
4

1 回答 1

1

尝试更改此行:

Uri screenshotUri = Uri.parse(pathim);

进入:

Uri screenshotUri = Uri.fromFile(file);

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

于 2012-02-02T08:30:52.657 回答