Xamarin.Android SD卡读取System.UnauthorizedAccessException
参数
//context
//test.zip
//"/storage/emulated/0/"
代码
public static void CopyToSD(Context ctx, string fileName,string outPath)
{
outPath = outPath + "/" + fileName;
Java.IO.File ttf = new Java.IO.File(outPath);//ROOT_FONT_SRC
if (!ttf.ParentFile.Exists())
{
ttf.ParentFile.Mkdirs();
}
try
{
using (System.IO.Stream fsRead = ctx.Assets.Open(fileName))
{
byte[] buffer = new byte[1024];
int length;
while ((length = fsRead.Read(buffer, 0, buffer.Length)) > 0)
{
报错语句: System.IO.FileStream dbOut = new System.IO.FileStream(outPath, System.IO.FileMode.Append);//ROOT_FONT_SRC
dbOut.Write(buffer, 0, buffer.Length);
}
}
}
catch (Exception e1)
{
//e.printStackTrace();
}
}
报错语句处提示:System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/test.zip" is denied
查了下,意思说是权限问题,然后 manifest.xml 配置如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="cn.x189.sh.caimomo" android:installLocation="auto">
<uses-sdk android:minSdkVersion="23" />
<application android:label="CaiMoMo"></application>
<uses-permission android:name="android.permission.INTERNET" />
<!-- SDCard中创建与删除文件权限 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<!-- 向SDCard写入数据权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
还说解决不了问题,求大牛帮帮忙,本人自学新手,全程百度,一脸蒙比,有教程地址什么的跪求一个。