Android创建并更新通知栏通知
16lz
2021-01-25
id为通知的唯一标识,如果多次创建id相同的通知,则只保留最后一次创建的通知。更新通知也是采用这个机制来实现的。
void showNotification(int id, String title, String subText, int progress) { NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle(title); mBuilder.setContentText(subText); mBuilder.setSmallIcon(R.mipmap.ic_launcher); mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); mBuilder.setProgress(100, progress, false); Notification notification = mBuilder.build(); mNotificationManager.notify(id, notification); }
更多相关文章
- Android源码阅读之Looper
- Android:SystemUi有关notification
- Android(安卓)Notification.Builder通知案例分享
- WebView设置之WebViewClient
- Android(安卓)Touch 事件的分发和消费机制
- 【Android】通知的实现
- 解析Android消息处理机制 ——HandlerThread/Looper & MessageQu
- Android(安卓)View 绘制流程之四:绘制流程触发机制
- Android(安卓)Binder机制(一)