虽然权限显然已正确设置,但无法在外部存储中创建目录 [英] Cannot create directory in external storage although permissions are apparently set correctly

查看:174
本文介绍了虽然权限显然已正确设置,但无法在外部存储中创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

但是我在尝试创建目录时失败

in my manifest file, however I fail when trying to create a directory

    Log.d(LOG_STRING, android.os.Environment.getExternalStorageState() );
    java.io.File folder = new java.io.File(Environment.getExternalStorageDirectory() + java.io.File.separator + "test");
    boolean success = true;
    if (!folder.exists()) {
        success = folder.mkdir();
    }
    if (success) {
        Log.d(LOG_STRING, "Created directory");
    } else {
        Log.d(LOG_STRING, "FAILED WHILE CREATING DIRECTORY");
    }

外部存储的状态为已挂载,但 test 目录无法创建,输出为FAILED WHILE CREATING DIRECTORY

The status of external storage is "mounted", but the test directory cannot be created and the output is "FAILED WHILE CREATING DIRECTORY".

在手机中浏览应用信息,我的应用程序标记为修改或删除USB存储设备内容权限。

Browsing in the phone to the "App Info", the permission "modify or delete the contents of your USB storage" is marked to be activated for my application.

这可能是什么原因?手机的一些特殊设置?这是搭载Android 4.3(API18)的三星GT-I9506。需要注意的是, getExternalStorageDirectory 不在SD卡上,而是在内部存储上( / storage / emulated / 0 / )。

What could be the cause of this? Some special setting of the phone? It's a Samsung GT-I9506 with Android 4.3 (API18). To be noted is that the getExternalStorageDirectory is not on the SD card, but on the internal storage (/storage/emulated/0/).



更新:

与同事交谈时,似乎这个设备在被植根之后经历了几次调整(允许特定的应用程序直接在SD卡上写入)。可能不值得进一步调查,我只需切换到另一台设备。我会保留设备一段时间,如果有人会出现答案,我会快速测试它是否能解决问题。

Speaking with colleagues, it seems that this device has undergone several tweaking after having been rooted (to allow a specific application to directly write on the SD card). It's probably not worth to investigate further, I will simply switch to another device. I'll keep the device for a while and if anybody will show up with an answer I will quickly test if it solves the problem.



更新2 :(赏金结束)

问题仍未解决,但如前所述,这很可能是针对此问题的设备。它不可能在任何路径上写入,无论是外部存储还是内部存储,甚至不在 getExternalCacheDir()返回的路径中。

The problem remains unsolved, but as stated before, it is most likely something very specific to this one device. It's not possible to write on any path, being it external or internal storage, not even in the path returned by getExternalCacheDir().

推荐答案

在我的情况下,我必须去设置 - >应用 - > NameOfApp - >权限并激活存储权限。如果我拥有AndroidManifest.xml上的所有权限,我不知道为什么默认情况下会停用它。我使用的是Android Marshmallow 6.0的Moto G(第3代)。

In my case I had to go under Settings -> Apps -> NameOfApp -> Permissions and activate the Storage permissions. I don't know why this comes deactivated by default if I have all the permissions on AndroidManifest.xml. I'm on a Moto G (3rd Gen) with Android Marshmallow 6.0.

这篇关于虽然权限显然已正确设置,但无法在外部存储中创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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