【发布时间】:2017-02-22 18:38:05
【问题描述】:
我正在使用此代码共享图像:
File file = ImageLoader.getInstance().getDiskCache().get(imageUrl);
if (file != null && file.exists()) {
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(Intent.createChooser(intent, "Send"));
} else {
Toast.makeText(context, "Image cannot be shared", Toast.LENGTH_SHORT).show();
}
我之前使用UIL加载图像,所以mageLoader.getInstance().getDiskCache().get(imageUrl);从磁盘缓存返回图像文件。
Gmail、环聊、消息、云端硬盘等可以抓取文件,但在 Google+ 上,当 Whatsapp 说“不支持这种格式”时,抓取不到文件。但是,如果我 save the file 到 Downloads 文件夹并通过 Gallery 应用程序共享,Google+ 和 Whatsapp 都会选择相同的图像。
【问题讨论】: