更改Google TV上的频道

时间:2013-03-24 02:40:23

标签: android parsing uri google-tv

我正在尝试为Google TV编写一个简单的应用程序,它会生成1-10的随机数,然后随机选择一个频道(501-510)并加载它。

我已经尝试过官方的google文档但官方示例项目没有编译。我还阅读了Is the GTV Channel Listing/Change API/Sample is broken on LG G2?,并尝试将其改编为谷歌版本,但应用程序在加载时崩溃。

我确定这必须是一个简单的修复。我不需要使用https://developers.google.com/tv/android/docs/gtv_provider上的教程获取有关频道的信息或搜索频道。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

如果您使用下面的代码,那么对提供程序的访问权已发生了变化。

权限:

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

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

    }