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

直播平台源码,各个样式的消息通知栏显示方式
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);
 
}

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

猜你喜欢

转载自blog.csdn.net/yb1314111/article/details/125371758