创建包目录中../Android/data在SD卡上否认Android和GT; 4.4 [英] Create package directory in ../Android/data denied on SD-Cards on Android >4.4

查看:242
本文介绍了创建包目录中../Android/data在SD卡上否认Android和GT; 4.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦从应用程序里面/存储/ extSdCard / Android的/数据创建我的应用程序的com.foo.Example文件夹中。如果使用文件管理器手动创建没有烦恼,只是创造了第一个用一个简单的mkdir返回false。
我用包名在清单申报和整个使用,我有合适的WRITE_EXTERNAL_STORAG​​E许可权在那里以及。
哪里是这个文件夹suposed来自,如果应用程序是无法创建它吗?

I have trouble creating the "com.foo.Example" folder of my app in "/storage/extSdCard/Android/data" from inside the app. If created manually with a file manager there is no trouble, just creating the first one with a simple mkdir returns false. I used the package name declared in the manifest and used throughout and I do have the appropriate WRITE_EXTERNAL_STORAGE-permission in there aswell. Where is this folder suposed to come from, if the app is unable to create it?

推荐答案

我假设你使用 getExternalFilesDir(),如果没有,你要转换到它。 getExternalFilesDir(),通过空时,将为您的应用程序写入,如果它不存在,并返回处理其私人目录。

I'm assuming you're using getExternalFilesDir(), if not, you'll want to convert to it. getExternalFilesDir(), when passed null, will create a private directory for your application to write to if it doesn't already exist and return the handle for that.

您会想看看本指南,其中有你需要关于如何编写到外部存储中的所有信息。

You'll want to check out this guide, which has all the info you need on how to write to external storage.

至于为什么你遇到的奇巧这个问题上,谷歌改变了外部存储到prevent应用程序的权限模型从编写到任意文件夹在SD卡,它提供了更好的安全性上,以及保持更好的东西主办。然而,最酷的部分是, getExternalFilesDir()甚至不需要许可使用!它总是提供给您的应用程序。

As for why you're having this issue on KitKat, Google changed the permission model for external storage to prevent apps from writing to arbitrary folders on the SD card, which provides better security, as well as keeping things better organised. However, the cool part is that getExternalFilesDir() doesn't even require a permission to use! It's always available to your application.

希望帮助!

这篇关于创建包目录中../Android/data在SD卡上否认Android和GT; 4.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆