簡體   English   中英

System.UnauthorizedAccessException拒絕錯誤

[英]System.UnauthorizedAccessException Denied Error

使用我的應用程序啟動模擬器時,出現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

即使您已在清單中啟用了READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE權限,您可能也需要在代碼中明確地做一些事情。 你已經在做嗎?

詳情請見下文

Xamarin-System.UnauthorizedAccessException:拒絕訪問路徑

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM