如何解决在Xamarin Android中将目标设置为Android 10 API级别29时无法下载文件
使用xamarin表单并将Target Android Version更改为Android 10.0 API级别29。我正在从服务器下载pdf ZIP文件并保存在外部存储中。因此,这在Android 9之前可以正常使用,但在Android 10设备中无法下载内容。我在manifest.xml中添加了android:requestLegacyExternalStorage =“ true”。现在,我可以在外部存储中使用包名称创建目录。所以我给了下载管理器这条路。当下载管理器开始下载时,显示java.lang.securityException。并且消息是不受支持的路径。
string extension = FetchFileExtension(downloadPath.ContentUrl.ContentType);
string path = Path.Combine(DependencyService.Get<Interfaces.IPath>().InternalStoragePath(),productId + extension);
IDownloadManager downloadManager = CrossDownloadManager.Current;
downloadManager.PathNameForDownloadedFile = new Func<IDownloadFile,string>(file =>
{
return path;
});
FetchLaunchData(productId);
IDownloadFile downloadFile = downloadManager.CreateDownloadFile(downloadPath.ContentUrl.Offline);
_activeDownloads[productId] = downloadFile;
downloadFile.PropertyChanged += PropertyChangedEventHandler;
downStartTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
downloadManager.Start(downloadFile);
public string StoragePath()
{
return Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/." + Assets.AppConst.ApplicationId + "/";
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。