试图分享意图Android的形象 [英] Trying to share image with intent Android
问题描述
我想的意图,社交媒体分享图片。它要求的路径形象,我已经从我的对象中获取图像的URL,在形式<$c$c>files.parsetfss.com/77c6003f-0d1b-4b55-b09c-16337b3a2eb8/tfss-7267d2df-9807-4dc0-ad6f-0fd47d83d20f-3eb7b9e4-d770-420c-a0a0-9ca4fc4a6a0a_1.png$c$c>,例如。份额的意图显示,但是当我打开任何其他应用分享,我得到任何的logcat错误崩溃。可能是什么回事?
意图份额=新意图(Intent.ACTION_SEND);
share.setType(图像/ *);
share.putExtra(Intent.EXTRA_STREAM,marketFeedItem.getDesign()的getImage());
startActivity(Intent.createChooser(份额,与我们分享您的设计!));
更新答案这是我做过什么来得到它的工作:
ImageView的ImageView的=(ImageView的)feedItemView.findViewById(R.id.image);
可绘制mDrawable = imageView.getDrawable();
位图mBitmap =((BitmapDrawable)mDrawable).getBitmap(); 字符串路径= MediaStore.Images.Media.insertImage(getContentResolver()
mBitmap,设计,NULL); URI URI = Uri.parse(路径); 意图份额=新意图(Intent.ACTION_SEND);
share.setType(图像/ *);
share.putExtra(Intent.EXTRA_STREAM,URI);
share.putExtra(Intent.EXTRA_TEXT,我发现一些很酷的东西!);
startActivity(Intent.createChooser(份额,与我们分享您的设计!));
如果的getImage()
返回了你在你的问题有一长串,这不是一个有效的URL,因为它缺少一个方案。
根据的文档,你需要传递内容:
乌里
在 EXTRA_STREAM
额外的费用。在实践中,文件:
乌里
也经常起作用。我希望你碰到与其他方案的问题,如 HTTPS:
或 HTTP:
I'm trying to share an image with an intent to social media. It's asking for the path to the image, and I've retrieved the image URL from my object, in the form of files.parsetfss.com/77c6003f-0d1b-4b55-b09c-16337b3a2eb8/tfss-7267d2df-9807-4dc0-ad6f-0fd47d83d20f-3eb7b9e4-d770-420c-a0a0-9ca4fc4a6a0a_1.png
, for example. The share intent displays but when I open any other app to share, I get a crash with no logcat error. What could be going wrong?
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!"));
Updated Answer. This is what I did to get it to work:
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!"));
If getImage()
is returning the long string that you have in your question, that is not a valid URL, as it lacks a scheme.
According to the docs, you need to pass a content:
Uri
in the EXTRA_STREAM
extra. In practice, a file:
Uri
frequently also works. I would expect you to run into problems with other schemes, like https:
or http:
.
这篇关于试图分享意图Android的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!