在Xamarin Android中将目标设置为Android 10 API级别29时无法下载文件

问题描述

enter image description here

使用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 (将#修改为@)