Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a File Dialog in Android TV Leanback

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.

like image 435
biscuitstack Avatar asked Aug 01 '16 18:08

biscuitstack


People also ask

What is leanback Library Android TV?

These libraries include the following: The Leanback library provides UI templates that simplify creating Android TV apps. The Leanback Preferences library provides preferences and settings screens that are consistent with the platform but can be themed to match your app.

What is Androidx Leanback?

// leanback-preference is an add-on that provides a settings UI for TV apps. implementation("androidx.leanback:leanback-preference:$leanback_version") // leanback-paging is an add-on that simplifies adding paging support to a RecyclerView Adapter.

What is leanback app?

Leanback: The v17 Leanback Support Library is a standard Android support library focused on providing APIs and widgets to simplify the development of TV apps. Most of the components used in a Leanback-enabled project are contained in this library. RecyclerView: This library provides the RecyclerView class.


1 Answers

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)

like image 71
Michael Sotnikov Avatar answered Oct 16 '22 17:10

Michael Sotnikov