Skip to content Skip to sidebar Skip to footer

How To Access The Entire Tv Provider Database By Tv Input Manager?

According to the Android docs TV Inputs provided and signed by the device manufacturer (signature apps) or other apps installed in the system partition will have access to the ent

Solution 1:

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:

  • If TV Provider supported by our system.
  • If All the Manifest Permission set to the application
  • If Application installed under the system apps (and has right SE Policy)

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.
 */publicstatic List<Channel> getChannels(ContentResolver resolver) {
    List<Channel> channels = newArrayList<>();
    // TvProvider returns programs in chronological order by default.Cursorcursor=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;
}

Another ex.

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

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

    ContentResolvercr= getContentResolver();
    Iterator<TvInputInfo> it = list.iterator();
    while(it.hasNext()) {
        TvInputInfoaux= it.next();
        Uriuri= TvContract.buildChannelsUriForInput(aux.getId());

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

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

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

    }

UPDATE:

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

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

Post a Comment for "How To Access The Entire Tv Provider Database By Tv Input Manager?"