5

I am developing an android app that targets android tv and part of the app requirement is that users need to save files on the SD card. To access the file system, I am trying to use Storage Access Framework (SAF). To test using SAF, I created a sample activity. Here is the code which I use to launch the file browser activity:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        startActivityForResult(i, REQUEST_CODE);

Then on the onActivityResult method I display a simple toast just for testing purposes. Here is the method

    @Override
    public void onActivityResult(int requestCode, int resultCode,
                                 Intent resultData) {

        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE) {

            Uri uri = null;
            if (resultData != null) {
                uri = resultData.getData();
            }
            Toast.makeText(this, "Path: " + uri.getPath(), Toast.LENGTH_LONG).show();
       }

When testing the sample activity that has the above code on my mobile phone (Android 5.0) it works successfully. However, testing it on android tv box and also android tv emulator (both Android 6.0), I get the following exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT typ=/ }

Isn't Storage Access Framework not supported on android tv? What can I do to resolve this issue

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
xabush
  • 849
  • 1
  • 13
  • 29
  • What Android TV device are you testing on? – CommonsWare Dec 06 '17 at 17:17
  • I am using mbox device model number S905x. I did also try on Android TV Emulator and Bhutan got the same error. Both of these have Android 6.0 – xabush Dec 06 '17 at 18:41
  • Hmmm... I do not have an Android TV environment right now to run some tests. I do not recall the documentation discussing this limitation. On the other hand, I can see where they might not have created a TV-friendly UI for browsing storage volumes. You may need to fall back to a [file-chooser library](https://android-arsenal.com/tag/35) for devices that lack this activity. – CommonsWare Dec 06 '17 at 20:30
  • I opted to use the storage access framework after having this [issue](https://github.com/spacecowboy/NoNonsense-FilePicker/issues/98) with a file-picker [library](https://github.com/spacecowboy/NoNonsense-FilePicker/) I was using. Let me try the others you suggested – xabush Dec 07 '17 at 08:42
  • 1
    It's unsupported on Android TV. Please check my related comment: https://stackoverflow.com/questions/38705316/implementing-a-file-dialog-in-android-tv-leanback/38715569#38715569 – Michael Sotnikov Dec 07 '17 at 22:33
  • FWIW, `ACTION_OPEN_DOCUMENT` works fine on an NVIDIA Shield 2017. – CommonsWare Dec 12 '17 at 21:55

0 Answers0