2

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:

  1. Storage Access Framework: This is the first method I come up with, but SAF is not supported on Android TV.
  2. 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.
  3. Opt out of scoped storage: Change targetSdkVersion to 29 and set requestLegacyExternalStorage="true". The only working method I found so far.
  4. 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.
anenasa
  • 61
  • 4
  • "I want to use MANAGE_EXTERNAL_STORAGE permission to access files" -- that may preclude you from distributing the app on the Play Store and elsewhere. "Is MANAGE_EXTERNAL_STORAGE not supported on Android TV" -- that is probably a true statement. Many Android TV devices have limited storage; Google is not encouraging developers to deal with much in the way of local files. "I also tried some alternatives" -- use `getExternalFilesDir()` (method on `Context`). – CommonsWare Jan 31 '23 at 14:43
  • @CommonsWare Thanks for your reply. "that may preclude you from distributing the app on the Play Store and elsewhere" -- I only distribute on github, so that doesn't matter. "use getExternalFilesDir()" -- I forget to mention that 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. (I suggested my users to use `adb push` to copy file from computer to TV, but one said that he didn't have a computer.) I will update my question. – anenasa Feb 01 '23 at 13:55

1 Answers1

1

Since there is no answer for a month, I will answer my question.

After testing on multiple versions of Android TV in emulator, I found that MANAGE_EXTERNAL_STORAGE is only available in Android TV 13, not in Android TV 11 and 12.

anenasa
  • 61
  • 4