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

查看:35
本文介绍了在 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类似幻灯片的用户体验的评论)感觉有点不雅,但看起来我别无选择?其次,我在 中没有看到任何文件对话框小部件引导操作.也许我错过了它,否则 Google 热衷于将文件直接选择在线而不是本地.

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 的所有子目录中的 mp3flac 文件,然后将路径、元数据等添加到我已经在处理虚拟数据的 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.

我想我对实现扫描有一些了解(谷歌提供了示例)并且已经成功地实现了将虚拟数据插入到数据库中.我似乎无法管理的是提供一种简单的方法,让用户使用 Android TV 的 Leanback 库选择要扫描的路径.显然,这在 Leanback 中不可用.有没有一种方法可以实现这不是噩梦?我正在寻找尽可能简单的目录选择对话框.如果它必须使用整个选项页面,ala 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天全站免登陆