Xamarin.Android SD卡的读写System.UnauthorizedAccessException

qq_32726357 2017-06-27 10:49:35

//参数
//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
{
//ttf.CreateNewFile();
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);
}



UnZip(outPath, "/data/user/0/cn.x189.sh.caimomo/files/", null);
}


}
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>

可问题还是存在,求大牛帮帮忙,本人自学Xamarin中,全程百度,一脸蒙币,谁有教程跪求分享,谢谢各位大牛们!!
...全文
1912 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_32726357 2017-06-27
  • 打赏
  • 举报
回复
跪求大牛,求大牛快点看到

436

社区成员

发帖
与我相关
我的任务
社区描述
欢迎来到Xamarin技术交流论坛学习交流,Xamarin是一个行动App开发平台,开发人员透过Xamarin可开发出iOS、Android 与Windows 等平台的...
社区管理员
  • Xamarin技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧