java - Android Share Intent Image Sharing 无法正常工作,除了 WhatsApp
问题描述
我检查了uri,保存的文件是位图及其返回文件。但分享时显示的图片无效。Gmail 说它无法附加附件,消息应用程序无法加载图像。
文本共享工作正常。
我是 Android 新手,通过共享意图共享图像时遇到问题。我用谷歌搜索了很多,尝试了各种方法,但仍然找不到解决方案。
public static void shareWallpaper(Context context, int wallpaperResourceId) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), wallpaperResourceId);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/wallpaper" + String.valueOf(wallpaperResourceId) + ".jpg";
OutputStream out = null;
File file = new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.getPath()));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
context.startActivity(Intent.createChooser(shareIntent, "برنامه مورد نظر خود را انتخاب کنید"));
}
解决方案
推荐阅读
- regex - 使用 linux 命令在会话日志文件中搜索工作流名称
- javascript - 在 2 个反应组件之间的提升状态出现错误需要并尝试在 2 个组件之间传递的各种方法
- clips - 语法错误 检查 Clips ide 中 deftemplate 的适当语法
- c++ - 如何传递可变参数模板函数?
- mysql - SQL Query 从表中获取不同的值以及有序行之间的差异
- c# - 找不到与输入匹配的已安装模板,在线搜索匹配的模板
- c++ - 输入和输出文件流在 C++ 中究竟是如何工作的
- spring-boot - 使用 TIBCO EMS EXPLICIT_CLIENT_DUPS_OK_ACKNOWLEDGE 的 Spring JMS 确认行为
- javascript - 我可以将我的 discord 机器人的控制台日志打印到 discord.js 中的特定通道吗?
- javascript - 为什么我的 .env 变量在 Parcel 中不起作用?