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.
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)
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.
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.
来源:https://stackoverflow.com/questions/38705316/implementing-a-file-dialog-in-android-tv-leanback