I have an Android application, and I want to get the user’s permission to read and write to the internal storage. The SDK specifications are: min: 23, target: 35. However, it’s not working. Does anyone know why?
i use <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
but not working
2
Answers
WRITE_EXTERNAL_STORAGE is deprecated for Android 11+ (API 30+).
If you want to access the storage then use scoped storage, for sepcific use cases you can follow:
• For app-specific files: context.getExternalFilesDir().
• For shared media: Use MediaStore.
• For file picking: Use Storage Access Framework (SAF) with Intent.ACTION_OPEN_DOCUMENT.
Add runtime permissions for READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, or READ_MEDIA_AUDIO for API 33+.
Avoid android:requestLegacyExternalStorage unless targeting API < 30.
If you’re talking about external storage, you can set the app target SDK version to 29 (30 or less) so that it can read and write in the /sdcard/ directory via the WRITE_EXTERNAL_STORAGE with READ_EXTERNAL_STORAGE permission. This relies on Android’s compatibility with lower versions of apps.
The directory can also be authorized using Android SAF.