public List<Channel> getCurrentChannels(Context mContext) {
        try {
            ApplicationInfo app = getApplicationContext().getPackageManager().getApplicationInfo(getApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
            Bundle bundle = app.metaData;
            final String service = bundle.getString("TvInputService");
            String channels = TvContract.buildInputId(new ComponentName(getPackageName(), service.substring(getPackageName().length())));
            Uri channelsQuery = TvContract.buildChannelsUriForInput(channels);
            Log.d(TAG, channels + " " + channelsQuery.toString());
            List<Channel> list = new ArrayList<>();
            Cursor cursor = null;
            try {
                cursor = mContext.getContentResolver().query(channelsQuery, null, null, null, null);
                while(cursor != null && cursor.moveToNext()) {
                    Channel channel = new Channel()
                            .setNumber(cursor.getString(cursor.getColumnIndex(TvContract.Channels.COLUMN_DISPLAY_NUMBER)))
                            .setName(cursor.getString(cursor.getColumnIndex(TvContract.Channels.COLUMN_DISPLAY_NAME)))
                            .setOriginalNetworkId(cursor.getInt(cursor.getColumnIndex(TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID)))
                            .setTransportStreamId(cursor.getInt(cursor.getColumnIndex(TvContract.Channels.COLUMN_TRANSPORT_STREAM_ID)))
                            .setServiceId(cursor.getInt(cursor.getColumnIndex(TvContract.Channels.COLUMN_SERVICE_ID)))
                            .setVideoHeight(1080)
                            .setVideoWidth(1920)
                            .setPrograms(getPrograms(getApplicationContext(),
                                    TvContract.buildChannelUri(cursor.getInt(cursor.getColumnIndex(TvContract.Channels._ID)))));
                    list.add(channel);
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
            return list;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
public List < Channel > getCurrentChannels ( Context mContext ) { try { ApplicationInfo app = getApplicationContext ( ) . getPackageManager ( ) . getApplicationInfo ( getApplicationContext ( ) . getPackageName ( ) , PackageManager . GET_META_DATA ) ; Bundle bundle = app . metaData ; final String service = bundle . getString ( "TvInputService" ) ; String channels = TvContract . buildInputId ( new ComponentName ( getPackageName ( ) , service . substring ( getPackageName ( ) . length ( ) ) ) ) ; Uri channelsQuery = TvContract . buildChannelsUriForInput ( channels ) ; Log . d ( TAG , channels + " " + channelsQuery . toString ( ) ) ; List < Channel > list = new ArrayList < > ( ) ; Cursor cursor = null ; try { cursor = mContext . getContentResolver ( ) . query ( channelsQuery , null , null , null , null ) ; while ( cursor != null && cursor . moveToNext ( ) ) { Channel channel = new Channel ( ) . setNumber ( cursor . getString ( cursor . getColumnIndex ( TvContract . Channels . COLUMN_DISPLAY_NUMBER ) ) ) . setName ( cursor . getString ( cursor . getColumnIndex ( TvContract . Channels . COLUMN_DISPLAY_NAME ) ) ) . setOriginalNetworkId ( cursor . getInt ( cursor . getColumnIndex ( TvContract . Channels . COLUMN_ORIGINAL_NETWORK_ID ) ) ) . setTransportStreamId ( cursor . getInt ( cursor . getColumnIndex ( TvContract . Channels . COLUMN_TRANSPORT_STREAM_ID ) ) ) . setServiceId ( cursor . getInt ( cursor . getColumnIndex ( TvContract . Channels . COLUMN_SERVICE_ID ) ) ) . setVideoHeight ( 1080 ) . setVideoWidth ( 1920 ) . setPrograms ( getPrograms ( getApplicationContext ( ) , TvContract . buildChannelUri ( cursor . getInt ( cursor . getColumnIndex ( TvContract . Channels . _ID ) ) ) ) ) ; list . add ( channel ) ; } } finally { if ( cursor != null ) { cursor . close ( ) ; } } return list ; } catch ( PackageManager . NameNotFoundException e ) { e . printStackTrace ( ) ; } return null ; }
Goes into the TV guide and obtains the channels currently registered
@return An ArrayList of channels