如何点击我的按钮分享我的屏幕演员?

时间:2012-02-01 16:27:41

标签: android android-intent android-file screensharing

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

1 个答案:

答案 0 :(得分:1)

尝试更改此行:

Uri screenshotUri = Uri.parse(pathim);

成:

Uri screenshotUri = Uri.fromFile(file);

并将File file声明移至境外if()