java - 尝试与 Android Intent 共享图像

标签 java android android-intent parse-platform android-sharing

我正在尝试与社交媒体分享图片。它要求图像的路径,我已经从我的对象中以 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/

相关文章:

android - 拍照后相机 Activity 中的对话框

java - 将 Smali 值打印到 logcat

android - 添加动画 GIF 到电子邮件/短信/whatsapp

java - 在提高 Java 性能时我应该寻找什么?

android - 是否可以从 apk 文件中提取 google-services.json?

android - 在 NDK 版本 (android-ndk-r8-windows.) 上编译 protobuf-2.4.1 代码

android - 保存时从照片中获取 ID

android - 广播接收器 ACTION_SEND 未显示

java - 可靠地获取时差 - Android

java - Spring Batch 管理员挂起在部署时注册步骤执行