Implementing a File Dialog in Android TV Leanback
Asked Answered
C

3

11

I have a dirPath String variable that I want to be able to change to a directory of my choice for an Android TV app. I find the Leanback framework's slideshow-like interface a little cumbersome for subtler actions but I would like to stick to it when I can as I'm a complete beginner on Android and java in general.

So, trying to stick to best practices, I would like the user to be able to change dirPath to point to a directory of their choosing (dirPath is used as a variable to scan for music in the nominated directory and its subdirectories). On other platforms I would look for a standard file open dialog for the OS, but I can't seem to find one in the Leanback framework.

My best guess is using GuidedStepFragments. This feels a little inelegant to bring in an entire options page (see my earlier comment about leanback's slideshow-like UX) all for the sake of choosing a directory, but it looks like I have little choice? Secondly, I don't see any file dialog widget amongst the GuidedActions. Perhaps I've missed it, or else Google was keen to direct file choosing to online and not local.


Additional Information:

I'm attempting to scan for mp3 and flac files in all subdirectories of dirPath and then adding the paths, metadata etc. into an SQLite database that I already have working with dummy data. I'm avoiding mediastore as it has too many limitations, particularly its inability to access network shares, which would be desirable for me for NAS access.

Once the user has nominated a dirPath and a scan is started, I'll pass this to AsyncTask to run on a separate background thread from the UI.


To Summarise:

I'm attempting to scan the attached storage of an Android TV device for music files using AsyncTask in a different thread than the UI. The scan will be fed the dirPath String variable and will examine this path and all of its subdirectories for music files, which it will then pass onto a metadata extractor, before storing the relevant data in an SQLite database.

I think I have some understanding of implementing the scan (Google provides examples) and have successfully implemented inserting dummy data into a database. What I can't seem to manage is to provide a simple means of letting the user select the path(s) to scan using Android TV's Leanback library. Apparently this isn't available in Leanback. Is there a way I can implement this that isn't a nightmare? I'm looking for as simple a directory choosing dialog box as possible. If it has to use an entire option page, ala GuidedStepFragments, so be it.

Companion answered 1/8, 2016 at 18:1 Comment(0)
W
7

There is no such picker in Leanback library. if You decide to implement, please note, that Storage Access Framework isn't available in Android TV:

// from AOSP:
// cts/hostsidetests/appsecurity/test-apps/DocumentClient/src/com/android/cts/documentclient/
// DocumentsClientTest.java
private boolean supportedHardware() {
    final PackageManager pm = getInstrumentation().getContext().getPackageManager();
    if (pm.hasSystemFeature("android.hardware.type.television") || pm.hasSystemFeature("android.hardware.type.watch")) {
        return false;
    }
    return true;
}

You can check intent.ACTION_GET_CONTENT(with optional Intent.createChooser) to deligate it to other apps, but in my experience it doesn't work on Sony Android TV (still looking into it)

Wrongly answered 2/8, 2016 at 8:37 Comment(4)
Thanks Michael. Bittersweet, as I'm happy I didn't miss something obvious but sad this is the case. It's disappointing that the intent of Android TV appears to be encouraging developers to avoid local storage. Devices like the Shield are capable of a lot. I'm aware that this is still a feasible task, if longwinded, but out of my comfort zone so I may bounty up this question to get a solid starting point. Perhaps the answer (if there is one) will help you too.Companion
Hey @biscuitstack, Regarding path/file chooser, You can check github.com/spacecowboy/NoNonsense-FilePicker. With proper theme defined (I took colors from leanback theme) it looks OK over GuidedStepFragment UI. The only thing I've changed is to requestFocus in onLoadFinished, otherwise there're some issues with dpad navigation. Sadly I don't have enough reputation to write proper answer with source example.Wrongly
"that Storage Access Framework isn't available in Android TV" -- ACTION_OPEN_DOCUMENT is available on an NVIDIA Shield 2017, as I just tested it. Works pretty much as you would expect.Dietz
@Dietz and it's available on nvidia shield only. Tested with shield, mibox, sony tvs.Wrongly
M
0

Right now the Storage Access Framework is not part of Android TV, although it is possible to build your own file picker using the GuidedStepFragment to step through folders on the local file system until you find the one you want to select.

Mitchel answered 10/8, 2016 at 17:9 Comment(0)
S
0

You can use any already existing logic for file browsing and implement a dialog with custom view for your case. You can check Es File explorer app for reference. In Android TV you can implement and show to user any view that you wish. The mantra is 'nextFocusDown','nextFocusUP','nextFocusLeft' , 'nextFocusRight' for each view to have a easy navigation between ui components. If you want to present user with an edittext beware as there is no special keyboards like number keyboard etc., present for Leanback.

Simonasimonds answered 19/9, 2016 at 2:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.