我正在尝试与社交媒体分享图片。它要求图像的路径,我已经从我的对象中以 files.parsetfss.com/77c6003f-0d1b-4b55-b09c-16337b3a2eb8/tfss-7267d2df-9807- 的形式检索了图像 URL例如 4dc0-ad6f-0fd47d83d20f-3eb7b9e4-d770-420c-a0a0-9ca4fc4a6a0a_1.png
。显示了共享 Intent ,但是当我打开任何其他应用程序进行共享时,我遇到了没有 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!"));
最佳答案
如果 getImage()
返回您问题中的长字符串,那不是有效的 URL,因为它缺少方案。
根据 the docs ,你需要在 EXTRA_STREAM
extra 中传递一个 content:
Uri
。在实践中,file:
Uri
通常也有效。我希望您会遇到其他方案的问题,例如 https:
或 http:
。
关于java - 尝试与 Android Intent 共享图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35829949/