与ShareActionProvider共享BMP?

时间:2013-11-12 22:41:36

标签: java android image bmp

在我的应用中,我正在尝试与ShareActionProvider共享BMP。它不起作用。我做错了还是我需要将其转换为PNG(我不想处理文件)。如果是这样我该怎么办?感谢。

Bitmap bmp = qrUtil.create(WIFIQRCODE, pref2);
                isCodeGenerated = true;
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("image/png");
                intent.putExtra(Intent.EXTRA_STREAM, bmp);
                provider.setShareIntent(intent);

1 个答案:

答案 0 :(得分:0)

Intent.EXTRA_STREAM应该是指向您要使用的图像文件的URI;你不能只在那里添加Bitmap。你应该这样做:

Uri uri = Uri.fromFile(new File(getFilesDir(), "img.jpg"));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());

这将根据图像的实际位置而改变,但这是一般的想法。