1

私はこのコードを書きます:共有ボタンをクリックすると、はい、画面の写真はSDカードに保存されますが、FacebookまたはBluetoothで共有を押すと、見つからないと表示されます。写真を手動で選択した場合、共有できますが、画面を共有したい共有ボタンをクリックしたときの写真?これどうやってするの?

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 に答える