如何通过 TV Input Manager 访问整个 TV Provider 数据库?

编程入门 行业动态 更新时间:2024-10-27 06:23:04
本文介绍了如何通过 TV Input Manager 访问整个 TV Provider 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

根据 Android 文档

由设备制造商提供并签名的 TV Inputs(签名应用程序)或系统分区中安装的其他应用程序将具有访问权限到整个电视提供商数据库.此访问可用于构建应用程序来浏览和搜索所有可用的电视频道和程序.

TV Inputs provided and signed by the device manufacturer (signature apps) or other apps installed in the system partition will have access to the entire TV Provider database. This access can be used to construct apps to browse and search across all available TV channels and programs.

假设我以设备制造商的身份签名或在系统分区中安装了应用程序,我如何才能访问 TvProvider 及其频道信息?

Assuming I signed as device manufacturer or installed app in system partition, how can I access the TvProvider and thus its channel information?

val tifSupport: Boolean = packageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)
Log.d("XXX", "TIF Support ? $tifSupport")

这一行说的是真的.然后我运行这些行:

This line says true. Then I run these lines:

val tvInputManager = applicationContext.getSystemService(TV_INPUT_SERVICE) as TvInputManager?
Log.d("XXX", "TvInputManager $tvInputManager")

val il = tvInputManager?.tvInputList
Log.d("XXX", "TvInputList size --> ${il?.size}")

tvInputManager?.tvInputList?.forEach { info ->
    Log.d("XXX", "TvInputListInfo ${info.id} ${info.serviceInfo} # ${info.extras.size()}")
}

第一次打印日志

TvInputManager android.media.tv.TvInputManager@95728c2

TvInputManager android.media.tv.TvInputManager@95728c2

所以 tvInputManager 看起来有效.第二个显示 0 作为 TvInputList 大小,因此第三个日志(在 forEach() 中)打印.

so the tvInputManager looks valid. Second shows 0 as the TvInputList size and thus third log (in forEach()) is not printed at all.

推荐答案

你必须从 Android 的背景开始.文档中的提供者是指 ContentProvider,它将在 Android 中的进程之间共享信息.现在开始:

You have to start with background for Android. By provider in the doc, they mean ContentProvider, which will share information between process within Android. Now to start with:

如果我们的系统支持电视提供商.如果为应用程序设置了所有清单权限如果应用程序安装在系统应用程序下(并且具有正确的 SE 策略)

然后您将能够使用 ContentProvider 来获取您需要的所有类型的信息.要查看对 TVContent Provider 的全面支持,您可以参考 此文件(确保它与您的 Android 操作系统版本一致)和其他 AOSP 信息.例如

Then you will be able to use ContentProvider to fetch all kind of information you need. To see the full support for TVContent Provider you can refer to this file (ensure it's aligned with your Android OS version) and other AOSP information. For ex.

/**
 * Returns the current list of channels your app provides.
 *
 * @param resolver Application's ContentResolver.
 * @return List of channels.
 */
public static List<Channel> getChannels(ContentResolver resolver) {
    List<Channel> channels = new ArrayList<>();
    // TvProvider returns programs in chronological order by default.
    Cursor cursor = null;
    try {
        cursor = resolver.query(Channels.CONTENT_URI, Channel.PROJECTION, null, null, null);
        if (cursor == null || cursor.getCount() == 0) {
            return channels;
        }
        while (cursor.moveToNext()) {
            channels.add(Channel.fromCursor(cursor));
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to get channels", e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return channels;
}

另一个例子

TvInputManager tv = (TvInputManager)getApplicationContext().getSystemService(Context.TV_INPUT_SERVICE);

    List<TvInputInfo> list = tv.getTvInputList();
    String[] projection =  {
            TvContract.Channels._ID,
            TvContract.Channels.COLUMN_DISPLAY_NUMBER
    };

    ContentResolver cr = getContentResolver();
    Iterator<TvInputInfo> it = list.iterator();
    while(it.hasNext()) {
        TvInputInfo aux = it.next();
        Uri uri = TvContract.buildChannelsUriForInput(aux.getId());

        Log.d("TAG", uri.toString());
        Log.d("TAG", aux.toString());

        Cursor cur = cr.query(uri, projection, null, null ,null);
        Log.d("TAG", cur.toString());

        if(cur.moveToFirst()) {
            Log.d("TAG", "not empty cursors");
        }

    }

更新:

您应该拥有的基本权限(另请参阅官方文档a>):

The basic permission you should have(Also refer to the official documentation):

<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA" />
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
<uses-permission android:name="com.android.providers.tv.permission.ACCESS_ALL_EPG_DATA"/>

这篇关于如何通过 TV Input Manager 访问整个 TV Provider 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 00:48:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1032114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Input   TV   Provider   Manager

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!