How to Fix Folder Creation Issues on Android Marshmallow (6.0)?
Oct 24, 2024 am 03:48 AMMarshmallow Android Folder Creation Issues
Having trouble creating folders on Android 6.0 (Marshmallow)? You've come to the right place!
Some Marshmallow devices exhibit instability in creating new folders. While everything works fine on Android 5.0, on Marshmallow sometimes the creation succeeds and sometimes not. why is that?
Permission issues
Marshmallow introduces tighter control over external storage permissions. For Android M and higher, explicit user permission is required before using external storage. If you do not request this permission, your application will not be able to create the directory.
Solution
In order to successfully create a folder on Marshmallow, you need to request WRITE_EXTERNAL_STORAGE permission from the user. You can achieve it using the following code:
<code class="java">@Override protected void onCreate(Bundle savedInstanceState) { ... if (CheckPermission(MyDevIDS.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { // 拥有写入权限 createApplicationFolder(); } else { // 请求运行时权限 RequestPermission(MyDevIDS.this, Manifest.permission.WRITE_EXTERNAL_STORAGE, REQUEST_RUNTIME_PERMISSION); } }</code>
CheckPermission and RequestPermission are helper methods that check if the application has the WRITE_EXTERNAL_STORAGE permission and request it if it has not been granted yet.
<code class="java">public static void createApplicationFolder() { File f = new File(Environment.getExternalStorageDirectory(), File.separator + Config.VIDEO_COMPRESSOR_APPLICATION_DIR_NAME); f.mkdirs(); ... }</code>
With these changes, your application will be able to reliably create folders on Marshmallow and above.
The above is the detailed content of How to Fix Folder Creation Issues on Android Marshmallow (6.0)?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Top 4 JavaScript Frameworks in 2025: React, Angular, Vue, Svelte

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?

Node.js 20: Key Performance Boosts and New Features

How does Java's classloading mechanism work, including different classloaders and their delegation models?

Iceberg: The Future of Data Lake Tables

Spring Boot SnakeYAML 2.0 CVE-2022-1471 Issue Fixed

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?

How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?
