【发布时间】:2021-05-10 15:07:04
【问题描述】:
我在 Android Manifest 文件中拥有这些权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
也在运行时请求权限。
这是我的pdf下载代码
var documentsPath = (string)Android.OS.Environment.GetExternalStoragePublicDirectory("SHAZ");
string localPath = Path.Combine(documentsPath, filename);
File.WriteAllBytes(localPath, bytes);
这是我从安卓应用中得到的。
** {System.UnauthorizedAccessException:对路径“/storage/emulated/0/SHAZ/ABC.pdf”的访问被拒绝。 在 System.IO.FileStream..ctor(System.String 路径、System.IO.FileMode 模式、System.IO.FileAccess 访问、System.IO.FileShare 共享、System.Int32 bufferSize、System.Boolean 匿名、System.IO。 FileOptions 选项)[0x001aa] 在 /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:239 在 System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/jenkins/workspace/archive -mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:91 在 (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) 在 System.IO.File.InternalWriteAllBytes (System.String path, System.Byte[] bytes) [0x00000] 在 /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/ src/System.IO.FileSystem/src/System/IO/File.cs:429 在 System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes) [0x00039] 在 /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/ src/System.IO.FileSystem/src/System/IO/File.cs:420 在 SaveFile.cs:25 中的 SHAZ_HR_Payroll.Droid.Models.SaveFile.SaveFiles(System.String 文件名,System.Byte[] 字节)[0x00034] 在 SHAZ_HR_Payroll.Pages.Employee.EmployeeChangePasswrod.BtnDownload_Clicked(System.Object 发件人,System.EventArgs e)[0x000d7] 在 \XYZ.xaml.cs:84 } **
IDE:VS-2019 安卓版本:10 Xamarin 表单版本:5.0.0.1874
【问题讨论】:
-
这与下载无关。我觉得没什么。这与尝试在存储中创建文件有关。
-
是的,你是对的。保存文件系统时出现访问被拒绝的错误,尽管我给予了完全许可。
-
不,您请求了许可。但是您使用的是 Android 10 设备。
标签: android xamarin xamarin.forms xamarin.android