Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法在Gmail和Instagram中共享图像_Android_Share Intent - Fatal编程技术网

Android 无法在Gmail和Instagram中共享图像

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

我想通过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_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 "";
        }
    }