简体   繁体   English

Android 电视:获取频道列表

[英]Android Tv: get list of channels

I've installed the androidtv-sample-inputs so I can fake some Tv inputs and have some channels and I wanted to get information about that channels, however, when I query to get that information I get an empty cursors.我已经安装了 androidtv-sample-inputs,所以我可以伪造一些电视输入并有一些频道,我想获取有关该频道的信息,但是,当我查询以获取该信息时,我得到一个空光标。

What i've tried so far is:到目前为止我尝试过的是:

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

    }

I have already added the uses-permission and I've checked that the tv input are not pass-through.我已经添加了使用权限,并且我已经检查过电视输入不是直通的。

<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"/>

What kind of permission are you using ?你使用什么样的权限?

If your application isn't signatureOrSystem, you can only access your own channels and programs from queries to the TV provider.如果您的应用程序不是signatureOrSystem,则您只能通过向电视提供商查询来访问您自己的频道和节目。 All the queries you're doing are filtered on your package name.您正在执行的所有查询都根据您的包名称进行过滤。

I guess that the information you can retrieve from a channel are restricted to what is accessible from TvInputInfo.我猜您可以从频道中检索的信息仅限于可从 TvInputInfo 访问的信息。

Additionally to "com.android.providers.tv.xxx" EPG permissions needed in the manifest file, you must sign your .apk !除了清单文件中所需的“com.android.providers.tv.xxx”EPG 权限之外,您还必须签署您的 .apk ! Otherwise you will see all the TvInput available on your device but none of the channels composing these tvInput (and this, without any error returned ;-)).否则,您将看到设备上可用的所有 TvInput,但没有组成这些 tvInput 的频道(并且没有返回任何错误;-))。 Android Studio provides this features ('BUILD' menu entry then 'Generate Signed APK') see How to sign an android apk file Android Studio 提供此功能(“构建”菜单项,然后“生成签名的 APK”)请参阅如何签署 android apk 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM