我正在尝试从设备存储器访问一个文件。下面是代码
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版本是Jelly bean
使用Android.OS.Environment.ExternalStorageDirectory.Path代替Android.OS.Environment.ExternalStorageDirectory.AbsolutePath为我解决的问题
终于找到了问题
行android:maxSdkVersion="18"
造成的问题,我已将其删除并开始工作