I am developing app that accesses text files created by users on Android TV (I want to support Android 5 to 12). Since Android 11, requestLegacyExternalStorage is ignored, so I want to use MANAGE_EXTERNAL_STORAGE permission to access files.
This is my sample code:
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:" + BuildConfig.APPLICATION_ID));
startActivityForResult(intent,0);
Application works fine when I test on my phone, but it crashes on Android TV with this error:
AndroidRuntime: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION dat=package:io.github.anenasa.news.debug }
I also try ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
but I get a similar error. Is MANAGE_EXTERNAL_STORAGE
not supported on Android TV or I make a mistake somewhere?
Note: I also tried some alternatives:
- Storage Access Framework: This is the first method I come up with, but SAF is not supported on Android TV.
- MediaStore: Partially working, but I have to rename the extension from .txt to media types like .mp4, because this is for accessing media files but not text files.
- Opt out of scoped storage: Change targetSdkVersion to 29 and set requestLegacyExternalStorage="true". The only working method I found so far.
- getExternalFilesDir(): File I want to read is created by user, and they are unable to put the file in app-specific external storage since Android 11.