简体   繁体   English

尝试与Intent Android共享图像

[英]Trying to share image with intent Android

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. 它正在询问图像的路径,并且我已经从对象中检索了图像URL,形式为files.parsetfss.com/77c6003f-0d1b-4b55-b09c-16337b3a2eb8/tfss-7267d2df-9807-4dc0-ad6f-0fd47d83d20f-3eb7b9e4-d770-420c-a0a0-9ca4fc4a6a0a_1.png The share intent displays but when I open any other app to share, I get a crash with no logcat error. 显示共享意图,但是当我打开任何其他应用程序进行共享时,出现崩溃,没有logcat错误。 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. 如果getImage()返回的是问题中的长字符串,则该URL无效,因为它缺少方案。

According to the docs , you need to pass a content: Uri in the EXTRA_STREAM extra. 根据文档 ,您需要传递一个content: EXTRA_STREAM额外content: Uri In practice, a file: Uri frequently also works. 在实践中,一个file: Uri经常也起作用。 I would expect you to run into problems with other schemes, like https: or http: . 我希望您会遇到其他方案的问题,例如https:http:

URL of your parse server for the image file is not a valid for share intent, so save loaded bitmap temporary in your device then share image using that saved bitmap URL. 图像文件的解析服务器的URL对共享意图无效,因此,将加载的位图临时保存在设备中,然后使用保存的位图URL共享图像。 After image shared you can delete saved image from your device 共享图像后,您可以从设备中删除保存的图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM