【问题标题】:Android - Xamarin UnauthorizedAccessException: Access to the path "/storage/sdcard0/ deniedAndroid - Xamarin UnauthorizedAccessException:访问路径“/storage/sdcard0/被拒绝
【发布时间】:2017-07-17 07:19:34
【问题描述】:

我正在尝试从设备内存中访问一个文件。下面是代码

string directory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath);
string Mp3 = Path.Combine(directory, "root.txt");
Toast.MakeText(Activity , "directory: " + directory, ToastLength.Long).Show();
if (File.Exists(Mp3))
{
    string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "STRACK");
    File.Copy(Mp3, applicationFolderPath+ "/root.txt");
}
else
{
    Toast.MakeText(Activity, "directory: " + directory, ToastLength.Long).Show();
} 

AndroidManifest 文件也更改为

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="18" />

但我收到错误UnauthorizedAccessException: Access to the path "/storage/sdcard0/ denied

我的安卓版本是果冻豆

【问题讨论】:

标签: c# io xamarin.android android-4.2-jelly-bean


【解决方案1】:

使用 Android.OS.Environment.ExternalStorageDirectory.Path 代替 Android.OS.Environment.ExternalStorageDirectory.AbsolutePath 为我修好了

【讨论】:

    【解决方案2】:

    终于找到问题了

    line android:maxSdkVersion="18" 提出问题我已将其删除并开始工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2018-04-05
      相关资源
      最近更新 更多