直播平台源码,各个样式的消息通知栏显示方式

本文介绍了直播平台源码中三种消息通知栏的显示方式:浮动通知(依赖系统权限),带进度条通知(适配不同版本),以及消息类型通知(7.0以上)。详述了各版本API调整和通知设置细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直播平台源码,各个样式的消息通知栏显示方式
1、浮动通知

    /**
     * 浮动通知 在[5.0,8.0)的系统中浮动通知的产生条件
     * 是NotificationCompat.Builder中设置setPriority()的参数
     * 必须在NotificationCompat.PRIORITY_HIGH及以上并且有铃声或者震动才能有效果
     * 但在[8.0,8.0+)的时候因为NotificationChannel中的设置高于一切 所以
     * NotificationChannel中的importance必须要在NotificationManager.IMPORTANCE_HIGH及以上(!注意 此时会有默认的铃声和震动的效果哦~)
     * 5.0以下的系统就不支持啦
     *
     * @param noticationId
     * @param pendingIntent
     * @param largeIcon
     * @param smallIcon
     * @param ticker
     * @param subText
     * @param contentTitle
     * @param contentText
     * @param sound
     * @param vibrate
     * @param light
     */
    public void notifyHeadUp(int noticationId, PendingIntent pendingIntent, @DrawableRes int largeIcon, @DrawableRes int smallIcon, String ticker, String subText, String contentTitle, String contentText, boolean sound, boolean vibrate, boolean light) {
 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (notificationChannel.getImportance() < NotificationManager.IMPORTANCE_HIGH) {
                notificationChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);
                notificationManager.createNotificationChannel(notificationChannel);
            }
        }
//        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//
//
//        }
        builderNotification(pendingIntent, largeIcon, smallIcon, ticker, subText, contentTitle, contentText, NotificationCompat.PRIORITY_HIGH, sound, vibrate, light);
 
 
        notifyNotification(noticationId);
    }

2、带进度条通知

/**
 * 在5.0的系统以下没有进度条显示 8.0及以上显示进度条是没有铃声和震动的效果的
 *
 * @param noticationId
 * @param pendingIntent
 * @param largeIcon
 * @param smallIcon
 * @param ticker
 * @param subText
 * @param contentTitle
 * @param contentText
 * @param maxProgress
 * @param curProgress
 */
public void notifyProgress(int noticationId, PendingIntent pendingIntent, @DrawableRes int largeIcon, @DrawableRes int smallIcon, String ticker, String subText, String contentTitle, String contentText, int maxProgress, int curProgress) {
    builderNotification(pendingIntent, largeIcon, smallIcon, ticker, subText, contentTitle, contentText, NotificationCompat.PRIORITY_HIGH, false, true, false);
 
    if (curProgress >= maxProgress) {
        builder.setProgress(0, 0, false);
    } else {
        builder.setProgress(maxProgress, curProgress, false);
    }
 
 
    notifyNotification(noticationId);
}

3、消息类通知

/**
 * 发送一个消息类的通知7.0以上有效 7.0以下效果不友好
 *
 * @param noticationId
 * @param pendingIntent
 * @param largeIcon
 * @param smallIcon
 * @param ticker
 * @param subText
 * @param contentTitle
 * @param contentText
 * @param priority
 * @param sound
 * @param vibrate
 * @param light
 */
public void notifyMessageType(int noticationId, PendingIntent pendingIntent, @DrawableRes int largeIcon, @DrawableRes int smallIcon, String ticker, String subText, String contentTitle, String contentText, int priority, boolean sound, boolean vibrate, boolean light) {
 
    builderNotification(pendingIntent, largeIcon, smallIcon, ticker, subText, contentTitle, contentText, priority, sound, vibrate, light);
 
    builder.setStyle(new NotificationCompat.MessagingStyle(contentTitle).setConversationTitle("xx")
            .addMessage(new NotificationCompat.MessagingStyle.Message(contentText, System.currentTimeMillis(), "wo")));
 
    notifyNotification(noticationId);
 
}

以上就是直播平台源码,各个样式的消息通知栏显示方式, 更多内容欢迎关注之后的文章

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值