【发布时间】:2019-11-14 00:00:37
【问题描述】:
当我用我的应用程序启动我的模拟器时,我得到了UnauthorizedAccessException,它告诉我“Access to /storage/emulated/0/Download/MenuPlayer is denied”。
这仅在我尝试创建文件或打开文件夹以将文件下载到其中时发生。
我的 AndroidManifest.xml 代码是:
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
我试图访问它的代码是:
try {
/// Get the path to the downloads folder
var donwloadDir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
path = Path.Combine(donwloadDir.AbsolutePath, dirName);
dirInfo = new DirectoryInfo(path);
///Create a path to the config file folder.
configFilePath = Android.OS.Environment.GetExternalStoragePublicDirectory("").AbsolutePath + "/";
} catch(Exception e) {
Android.Util.Log.Debug(TAG, "STUFF HERE..." + configFilePath);
Android.Util.Log.Debug(TAG, e.Message);
System.IO.File.WriteAllText(@"C:\logs.txt", e.Message);
}
System.IO.File.WriteAllText(@"C:\logs.txt", Android.OS.Environment.DirectoryDownloads);
Android.Util.Log.Debug(TAG, configFilePath);
Android.Util.Log.Debug(TAG, "END | PlayerReader");
错误是:
未处理的异常:
System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/MenuPlayer" is denied. occurred
【问题讨论】:
标签: c# android xamarin emulation