0

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

我可以在WhatsAppFacebook中发送图像,但不能在GmailInstagram中发送。

尝试通过Gmail分享时,它显示给我

Can't attach file

对于Instagram,它向我展示了

无法加载图片

.

还需要添加shareIntent什么吗?

4

1 回答 1

1
File file = new File(Environment.getExternalStorageDirectory() + File.separator + yourFile.getRouteFile());
                        if (file.exists()) {
                            String fileExtension = FileExtension.getFileExtension(file);
                            Log.d(TAG, "fileExtension: " + fileExtension);
                            Uri uri = Uri.parse("file://" + file.getAbsolutePath());
                            Intent share = new Intent(Intent.ACTION_SEND);
                            share.putExtra(Intent.EXTRA_STREAM, uri);
                            share.setType(fileExtension + "/*");
                            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                            context.startActivity(Intent.createChooser(share, "Share file"));
                        }

获取文件扩展名

public static String getFileExtension(File file) {
        String name = file.getName();
        try {
            return name.substring(name.lastIndexOf(".") + 1);
        } catch (Exception e) {
            return "";
        }
    }
于 2017-08-25T09:27:31.093 回答