Home >Java >javaTutorial >Why Can't I Create Directories in Android 10 and How Can I Fix It?

Why Can't I Create Directories in Android 10 and How Can I Fix It?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-06 03:56:19184browse

Why Can't I Create Directories in Android 10 and How Can I Fix It?

Unable to create directory in Android 10

In Android 10, you may not be able to create directory. This is possible on devices older than Android Oreo.

Cause:

Android 10 and above has restricted default access to anywhere in external storage or removable storage. This includes Environment.getExternalStorageDirectory() and other Environment methods (for example, getExternalStoragePublicDirectory()).

Solution:

There are several ways to fix this issue:

  1. For Android 10 and 11 , use traditional storage mode:

    in the manifest file Add android:requestLegacyExternalStorage="true" to the element. This selects legacy storage mode and your existing external storage code will work.

  2. Use Context methods:

    Use methods on Context (for example, getExternalFilesDir()) to access directories on external storage, your Applications can write in it. No permissions are required to use these directories. However, once the app is uninstalled, the data stored in it will be deleted.

  3. Use storage access frameworks:

    Use storage access frameworks such as ACTION_OPEN_DOCUMENT and ACTION_CREATE_DOCUMENT.

  4. For media content, use MediaStore:

    If what you want to store is media content, you can use MediaStore to place the media in the standard media location .

The above is the detailed content of Why Can't I Create Directories in Android 10 and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn