Home >Java >javaTutorial >How to Address Directory Creation Issues in Android Marshmallow?
Directory Creation Issues in Android Marshmallow
Creating directories within an Android application typically involves utilizing the mkdirs() method. However, users have intermittently encountered directory creation issues in Android 6.0 (Marshmallow).
The issue arises from the stricter runtime permissions introduced in Marshmallow. This means that applications must explicitly request permission from the user to access external storage before performing tasks such as creating directories. Neglecting to request permission can result in the mkdirs() method failing.
To resolve this problem, the application should request the WRITE_EXTERNAL_STORAGE permission from the user at runtime. Here's an example of how to implement this permission check:
<code class="java">if (CheckPermission(MyDevIDS.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { // you have permission go ahead createApplicationFolder(); } else { // you do not have permission go request runtime permissions RequestPermission(MyDevIDS.this, Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_RUNTIME_PERMISSION); }</code>
The CheckPermission and RequestPermission methods check for and request the required permission, respectively. If the user grants permission, the application can proceed with directory creation. This approach ensures that the application has the necessary permissions to operate properly on devices running Android Marshmallow and beyond.
The above is the detailed content of How to Address Directory Creation Issues in Android Marshmallow?. For more information, please follow other related articles on the PHP Chinese website!