0

I am trying to write a simple app for Google TV which generates a random number from 1-10 then randomly selects a channel (501-510) and loads it.

I have tried the official google documentation but the official sample project doesnt compile. I have also read Is the GTV Channel Listing/Change API/Sample is broken on LG G2? and tried to adapt this into the google version however the app crashes on loading.

Im sure this must be a simple fix. I do not need to get information about the channel or search for them using the tutorial at https://developers.google.com/tv/android/docs/gtv_provider.

Any help greatly appreciated.

Community
  • 1
  • 1
EHarpham
  • 602
  • 1
  • 17
  • 34

1 Answers1

1

The access to the providers have changed if you use the code below things should improve.

Permissions:

<uses-permission android:name="com.google.android.tv.permission.READ_CHANNELS"/>
<uses-permission android:name="com.google.android.tv.mediadevices.permission.READ_STREAMS"/>

code:

 public abstract class ChannelList {

    private static ChannelList mCL=null;

    public abstract String getPROVIDER_URI();

    public abstract String getCALL_SIGN_COLUMN();

    public abstract String getURI_COLUMN();

    public abstract String getNUMBER_COLUMN();

    public abstract String getNAME_COLUMN();

    public static ChannelList getChannelList() {
        if (mCL != null)
            return mCL;

        int mGtvLibraryVersion = 0;
        try {
            Class<?> cl = Class.forName("com.google.android.tv.Version");
            mGtvLibraryVersion = cl.getField("GTV_SDK_INT").getInt(null);
        } catch (Exception ex) {}

        Log.d("Resolution Test", "Version " + mGtvLibraryVersion);

        mCL= mGtvLibraryVersion > 0 ? new Version3ChannelList(): new Version2ChannelList();
        return mCL;
    }

    /**
     * Use the getChannelList factory to obtain an instance of a subclass of
     * ChannelList
     */

    private ChannelList() {
    }

    @Override
    public String toString() {
        return "SDK Provider: " + getPROVIDER_URI() + "\n" +
                "Columns: " + getCALL_SIGN_COLUMN() + " " + getURI_COLUMN() + " " + getNUMBER_COLUMN() + " "
                + getNAME_COLUMN();
    }



    public static final class Version2ChannelList extends ChannelList {

        @Override
        public String getPROVIDER_URI() {
            return "content://com.google.android.tv.provider/channel_listing";
        }

        @Override
        public String getCALL_SIGN_COLUMN() {
            return "callsign";
        }

        @Override
        public String getURI_COLUMN() {
            return "channel_uri";
        }

        @Override
        public String getNUMBER_COLUMN() {
            return "channel_number";
        }

        @Override
        public String getNAME_COLUMN() {
            return "channel_name";
        }

    }

    public static final class Version3ChannelList extends ChannelList {


        @Override
        public String getPROVIDER_URI() {
            return "content://com.google.tv.mediadevicesapp.MediaDevicesProvider/channel_list";
        }

        @Override
        public String getCALL_SIGN_COLUMN() {
            return "subName";
        }

        @Override
        public String getURI_COLUMN() {
            return "url";
        }

        @Override
        public String getNUMBER_COLUMN() {
            return "channelNumber";
        }

        @Override
        public String getNAME_COLUMN() {
            return "name";
        }

    }