避免在Android 8.0的电视频道中创建重复频道

问题描述 投票:0回答:1

我正在使用Android 8.0及更高版本的电视频道,

我可以通过下面的代码在其电视频道上显示我的App频道

private void createChannel(Context c) {
    // NOTE : THESE INFO MUST MATCH WITH DATA IN MANIFEST.XML
    ComponentName cn = new ComponentName(c, MainActivity.class.getName());
    String channelInputId = TvContractCompat.buildInputId(cn);

    // Design Channel Data on Launcher in here
    Channel channel = new Channel.Builder()
            .setDisplayName("Video Hot")
            .setType(TvContractCompat.Channels.TYPE_PREVIEW)
            .setInputId(channelInputId)
            .setAppLinkIntent(new Intent(c, MainActivity.class))
            .build();

    Uri channelUri = c.getContentResolver().insert(
            TvContractCompat.Channels.CONTENT_URI, channel.toContentValues());
    if (channelUri != null && !channelUri.equals(Uri.EMPTY)) {
        long channelId = ContentUris.parseId(channelUri);

        Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), R.mipmap.ic_channel_logo);
        ChannelLogoUtils.storeChannelLogo(c, channelId, bitmap);

        // Request to show on Default Channel
        TvContractCompat.requestChannelBrowsable(c, channelId);

        NotificationManager notificationManager = (NotificationManager)
                c.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel mNcChannelMedia = new NotificationChannel(
                channelId + "", c.getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);

        notificationManager.createNotificationChannel(mNcChannelMedia);
    }
}

但是我不知道哪种方法可以检查已存在的通道,以避免出现以下图像中的重复问题

((清除数据应用程序设置后,再次打开应用程序,它已重复)

enter image description here

认识的人,

请帮助我,

谢谢,

android android-tv
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.