在Android TV Leanback中实现文件对话框 [英] Implementing a File Dialog in Android TV Leanback

查看:335
本文介绍了在Android TV Leanback中实现文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个dirPath String 变量,我希望能够将其更改为Android TV应用程序选择的目录.我发现Leanback框架的类似于幻灯片的界面对于微妙的操作有点麻烦,但是我希望在我可以成为Android和Java入门者的情况下坚持使用它.

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.

因此,为了坚持最佳实践,我希望用户能够更改dirPath指向他们选择的目录(dirPath用作变量来扫描指定目录中的音乐.及其子目录).在其他平台上,我会为操作系统寻找标准的文件打开对话框,但在Leanback框架中似乎找不到该对话框.

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.

我最好的猜测是使用 GuidedStepFragments .为了选择目录而引入整个选项页(请参阅我之前对leanback的类似幻灯片的UX的评论)感觉有点不雅,但似乎我别无选择?其次,在 GuidedActions .也许我错过了,否则谷歌渴望将文件选择直接引导到在线而不是本地.

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.

其他信息:

我正在尝试扫描dirPath的所有子目录中的 mp3 flac 文件,然后将路径,元数据等添加到SQLite数据库中我已经在使用虚拟数据了.我避免使用mediastore,因为它有太多限制,尤其是它无法访问网络共享,这对我来说是NAS访问所希望的.

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.

一旦用户指定了dirPath并启动了 scan ,我会将其传递给AsyncTask以在与UI分离的后台线程上运行.

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.

总结一下:

我正在尝试使用AsyncTask在与UI不同的线程中扫描Android TV设备的附加存储中的音乐文件.扫描将输入dirPath String 变量,并将检查此路径及其所有子目录中的音乐文件,然后将其传递到元数据提取器中,然后再将相关数据存储在SQLite数据库.

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.

我认为我对实现扫描有一定的了解(Google提供了示例),并且已经成功实现了将虚拟数据插入数据库的操作.我似乎无法管理的是提供一种简单的方法,让用户使用Android TV的 Leanback 库选择要扫描的路径.显然,这在 Leanback 中不可用.有什么办法可以实现我的梦想,这不是梦?以求的吗?我正在寻找一个尽可能简单的目录选择对话框.如果必须使用整个选项页,例如GuidedStepFragments,就这样.

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.

推荐答案

Leanback库中没有这样的选择器. 如果您决定实施,请注意,存储访问框架在Android TV中不可用:

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;
}

您可以选中intent.ACTION_GET_CONTENT(带有可选的Intent.createChooser)以将其绑定到其他应用程序,但以我的经验,它在Sony Android TV上不起作用(仍在研究中)

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)

这篇关于在Android TV Leanback中实现文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆