2017-07-17 82 views
0

我试图从设备存储器访问一个文件,下面是代码的Android - Xamarine UnauthorizedAccessException:对路径“/存储/ sdcard0 /否认

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

我的Android版本果冻豆

+0

看到这个问题:https://stackoverflow.com/questions/21707138/cannot-create-files-on-android-with-xamarin – Alexandre

回答

0

使用 Android.OS.Environment.ExternalStorageDirectory.Path 代替 Android.OS.Environment.ExternalStorageDirectory.AbsolutePath 是固定的,对我来说

0

发现了问题终于

线android:maxSdkVersion="18"使问题我已经删除它,并得到了工作