目录中的MonoDroid评估System.UnauthorizedAccessException.CreateDirectory()

时间:2012-05-03 10:41:58

标签: c# xamarin.android monodevelop mvvmcross

情景:

启动MonoDevelop

新的Android应用

使用

替换按钮单击委托
string fullPath = "/data/misc.mvvmcross.customermanagement/files/_Caches/Pictures.MvvmCross/";
if (System.IO.Directory.Exists(fullPath))
{
    button.Text = "exists";
}
else
{
    button.Text = "not found";
    Directory.CreateDirectory(fullPath);
}

运行并单击按钮。 Directory.CreateDirectory将失败并显示

System.UnauthorizedAccessException

尝试使用不同的API级别创建新的模拟器图像,但问题仍然存在

有人想过吗?

好的,已经创建了新的Android Emulator图像并使用了它。 一切现在都有效。

解决方案: 为您想要的API级别创建一个新的Android模拟器图像(不要忘记Google API支持)

1 个答案:

答案 0 :(得分:0)

我想知道这是否是由某种程序集/程序包命名问题引起的。

我测试了这段代码:

        string fullPath = Path.Combine(FilesDir.Path, "_Caches2/Pictures.MvvmCross/2/");
        if (System.IO.Directory.Exists(fullPath))
        {
            button.Text = "exists";
        }
        else
        {
            button.Text = fullPath;
            Directory.CreateDirectory(fullPath);
        }

...它在2.3.3模拟器中工作正常。

数据文件夹模式为:/data/ * package name * /files/

一个包不能访问另一个包的数据是正确的(我认为)。

所以我想知道你的软件包名称是否错误 - 检查应用程序的清单选项卡和manifest.xml文件?

相关问题