直播平台源码,各个样式的消息通知栏显示方式
直播平台源码,各个样式的消息通知栏显示方式
1、浮动通知
1 | /**<br> * 浮动通知 在[5.0,8.0)的系统中浮动通知的产生条件<br> * 是NotificationCompat.Builder中设置setPriority()的参数<br> * 必须在NotificationCompat.PRIORITY_HIGH及以上并且有铃声或者震动才能有效果<br> * 但在[8.0,8.0+)的时候因为NotificationChannel中的设置高于一切 所以<br> * NotificationChannel中的importance必须要在NotificationManager.IMPORTANCE_HIGH及以上(!注意 此时会有默认的铃声和震动的效果哦~)<br> * 5.0以下的系统就不支持啦<br> *<br> * @param noticationId<br> * @param pendingIntent<br> * @param largeIcon<br> * @param smallIcon<br> * @param ticker<br> * @param subText<br> * @param contentTitle<br> * @param contentText<br> * @param sound<br> * @param vibrate<br> * @param light<br> */ <br> 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) {<br> <br> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {<br> if (notificationChannel.getImportance() < NotificationManager.IMPORTANCE_HIGH) {<br> notificationChannel.setImportance(NotificationManager.IMPORTANCE_HIGH);<br> notificationManager.createNotificationChannel(notificationChannel);<br> }<br> }<br> // else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {<br>//<br>//<br>// }<br> builderNotification(pendingIntent, largeIcon, smallIcon, ticker, subText, contentTitle, contentText, NotificationCompat.PRIORITY_HIGH, sound, vibrate, light);<br> <br> <br> notifyNotification(noticationId);<br> } |
2、带进度条通知
1 | /**<br> * 在5.0的系统以下没有进度条显示 8.0及以上显示进度条是没有铃声和震动的效果的<br> *<br> * @param noticationId<br> * @param pendingIntent<br> * @param largeIcon<br> * @param smallIcon<br> * @param ticker<br> * @param subText<br> * @param contentTitle<br> * @param contentText<br> * @param maxProgress<br> * @param curProgress<br> */ <br> 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) {<br> builderNotification(pendingIntent, largeIcon, smallIcon, ticker, subText, contentTitle, contentText, NotificationCompat.PRIORITY_HIGH, false, true, false);<br> <br> if (curProgress >= maxProgress) {<br> builder.setProgress(0, 0, false);<br> } else {<br> builder.setProgress(maxProgress, curProgress, false);<br> }<br> <br> <br> notifyNotification(noticationId);<br> } |
3、消息类通知
1 | /**<br> * 发送一个消息类的通知7.0以上有效 7.0以下效果不友好<br> *<br> * @param noticationId<br> * @param pendingIntent<br> * @param largeIcon<br> * @param smallIcon<br> * @param ticker<br> * @param subText<br> * @param contentTitle<br> * @param contentText<br> * @param priority<br> * @param sound<br> * @param vibrate<br> * @param light<br> */ <br> 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) {<br> <br> builderNotification(pendingIntent, largeIcon, smallIcon, ticker, subText, contentTitle, contentText, priority, sound, vibrate, light);<br> <br> builder.setStyle( new NotificationCompat.MessagingStyle(contentTitle).setConversationTitle( "xx" )<br> .addMessage( new NotificationCompat.MessagingStyle.Message(contentText, System.currentTimeMillis(), "wo" )));<br> <br> notifyNotification(noticationId);<br> <br> } |
以上就是直播平台源码,各个样式的消息通知栏显示方式, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现