【发布时间】:2016-03-06 17:20:25
【问题描述】:
我正在尝试与社交媒体共享一张图片。它要求图像的路径,并且我已经从我的对象中检索了图像 URL,例如files.parsetfss.com/77c6003f-0d1b-4b55-b09c-16337b3a2eb8/tfss-7267d2df-9807-4dc0-ad6f-0fd47d83d20f-3eb7b9e4-d770-420c-a0a0-9ca4fc4a6a0a_1.png 的形式。共享意图显示,但是当我打开任何其他应用程序进行共享时,我遇到了没有 logcat 错误的崩溃。可能出了什么问题?
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, marketFeedItem.getDesign().getImage());
startActivity(Intent.createChooser(share, "Share your design!"));
更新的答案。这是我为使其正常工作所做的:
ImageView imageView = (ImageView) feedItemView.findViewById(R.id.image);
Drawable mDrawable = imageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(),
mBitmap, "Design", null);
Uri uri = Uri.parse(path);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.putExtra(Intent.EXTRA_TEXT, "I found something cool!");
startActivity(Intent.createChooser(share, "Share Your Design!"));
【问题讨论】:
-
那么
marketFeedItem.getDesign().getImage()返回一个URL或者位图? -
尝试改成
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(marketFeedItem.getDesign().getImage())); -
它肯定会打印出 url。
-
@Bhargav 这给出了 IllegalArgumentException。
-
异常消息说什么?只允许内容 Uri?
标签: java android android-intent parse-platform android-sharing