我正在使用Xamarin.Plugins.Messaging
nuget尝试发送带有附件的电子邮件。我遇到错误
Java.Lang.IllegalArgumentException:无法找到包含/data/data/com./files/Summary.pdf的已配置根目录
我已经按照说明设置了Android清单
<application android:icon="@drawable/icon" android:largeHeap="@bool/largeheap" android:label="<MyAppName>">
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="com.<MyAppName>.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
并将file_paths.xml
文件集添加到Android资源
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>
这是我用来将字节数组保存为文件并将其附加到电子邮件中的代码
var fileResult = await dal.getdoc(id); //REST call
File.WriteAllBytes(Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "BuyerSummary.pdf"), fileResult);
string fileName = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "BuyerSummary.pdf");
var email = new EmailMessageBuilder()
.Subject("Buyer Netsheet summary")
.Body(textSummary)
.WithAttachment(fileName, "application/pdf")
.Build();
emailMessenger.SendEmail(email);