gpt4 book ai didi

android - 如何通过编码将图像和.txt(多个文件)文件附加到gmail?

转载 作者:行者123 更新时间:2023-11-30 04:01:34 25 4
gpt4 key购买 nike

我正在尝试附加图像文件和 .txt 文件,但只有一个文件正在附加,一个没有附加如何附加这两个文件。如果我使用 ACTION_SEND_MULTIPLE,则应用会强制关闭。

这是我的代码:

public static Intent getSendEmailIntent(Context context, String email,
String subject, String body, String fileName) {


final Intent emailIntent = new Intent(Intent.ACTION_SEND);

// Explicitly only use Gmail to send
emailIntent.setClassName("com.google.android.gm",
"com.google.android.gm.ComposeActivityGmail");

emailIntent.setType("*/*");

// Add the recipients
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,
new String[] { email }
);

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);

// Add the attachment by specifying a reference to our custom
// ContentProvider
// and the specific file of interest
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/"+ "anything.txt"));
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/"+ "anything.jpg"));

return emailIntent;
}

如果我在返回之前最后放了一个 .jpg 文件,它是附加的。但是,如果我最后放了一个 .txt 文件,那么它就是附加的。我想附上这两个文件,请帮忙。

最佳答案

您可以只使用下面的代码并将文件路径更改为您的文件。

ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(Uri.fromFile(new File("/mnt/sdcard/Medplann/IMG.jpg"))); // Add your image URIs here
imageUris.add(Uri.fromFile(new File("/mnt/sdcard/Medplann/Report.pdf")));

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));

阅读此页:send

关于android - 如何通过编码将图像和.txt(多个文件)文件附加到gmail?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12422910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com