Android 无法在Gmail和Instagram中共享图像
我想通过shareIntent共享图像。我的代码如下:Android 无法在Gmail和Instagram中共享图像,android,share-intent,Android,Share Intent,我想通过shareIntent共享图像。我的代码如下: Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(list.get(position).getFilePath())); shareIntent.putExtra(android.content.Intent.EXTRA
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(list.get(position).getFilePath()));
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Sending from myApp");//gmail-subject
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Image 1234");//gmail-body
shareIntent.putExtra(Intent.EXTRA_TITLE, "Image 1234");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share via"));
我可以用WhatsApp和Facebook发送图片,但不能用Gmail或Instagram发送
当我试图通过Gmail分享时,它告诉我
无法附加文件
对于Instagram,它向我展示了
无法加载图像
在shareIntent中添加其他内容需要吗
获取文件扩展名
public static String getFileExtension(File file) {
String name = file.getName();
try {
return name.substring(name.lastIndexOf(".") + 1);
} catch (Exception e) {
return "";
}
}
这个很好用。但是有一个问题:share.setTypefileExtension+/*;由于这一行,它显示了与share.setTypeimage/*相比的可共享应用的小列表;只能使用图像,但我也可以使用share.setTypeimage/*共享文档;
public static String getFileExtension(File file) {
String name = file.getName();
try {
return name.substring(name.lastIndexOf(".") + 1);
} catch (Exception e) {
return "";
}
}