尝试检索某些文件时,我在 Android 上遇到 UnauthorizedAccessException
。奇怪的是,在今晚之前的几个月里它一直有效。
过去几个小时我做的唯一事情是(即使我看不出它如何改变了任何事情):
- 上传 apk 以启用 Google Play 服务的 Alpha 测试
- 添加 keystore 并对应用进行签名(尝试不签名,同样的问题)
- 正在删除测试设备上应用的最后一个实例(与签名版本不兼容)
该应用程序是使用 Unity 5.5.0f3 构建的,我使用 Application.persistentDataPath
构建我尝试访问的路径。
这是异常的调用堆栈:
UnauthorizedAccessException: Access to the path "/storage/emulated/0/Android/data/com.<mycompany>.<myproductname>/files/Saves" is denied.
at System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetFiles (System.String path, System.String searchPattern) [0x00000] in <filename unknown>:0
at System.IO.Directory.GetFiles (System.String path, System.String searchPattern, SearchOption searchOption) [0x00000] in <filename unknown>:0
at ProfileManager.ParseDirForProfiles (.DirName _dir, .FileExtension _ext) [0x00000] in <filename unknown>:0
at SaveManager.ParseDirForProfiles () [0x00000] in <filename unknown>:0
at myproductname.OnStart () [0x00000] in <filename unknown>:0
at StateMachine.Start () [0x00000] in <filename unknown>:0
最佳答案
该目录可能仍属于应用程序的先前不兼容版本。删除该目录并让您的应用在下次运行时重新创建它。
如果您的应用正常更新,就不会出现此类问题。
关于android - Android 上的 UnauthorizedAccessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41369960/