简体   繁体   中英

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.

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. 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.

Additionally to "com.android.providers.tv.xxx" EPG permissions needed in the manifest file, you must sign your .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 ;-)). Android Studio provides this features ('BUILD' menu entry then 'Generate Signed APK') see How to sign an android apk file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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