Home >Java >javaTutorial >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:
For Android 10 and 11 , use traditional storage mode:
in the manifest file Add android:requestLegacyExternalStorage="true" to the
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.
Use storage access frameworks:
Use storage access frameworks such as ACTION_OPEN_DOCUMENT and ACTION_CREATE_DOCUMENT.
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!