Notification的原生实现基本可以包括:
使用getSystemService(context.Notification_service) 获取 Notificationmanager 的引用
使用Notification Builder来构建 Notification
使用前面 的 NotificationManager 启动Notification
简单逻辑代码如下:
获取NotificationManager的引用:
NotificationManager nm = (NotificationManager) mcontext.getSystemService(Context.NOTIFICATION_SERVICE);
2. 构建 Notification
Notification.Builder builder = new Notification.Builder(mcontext);
builder.setWhen(System.currentTimeMillis()).setContentTitle("contentTitle").setContentText("contentText");
builder.setLargeIcon(bitmap).setSmallIcon(R.drawable.download_icon);
builder.setProgress(MaxLength,currentLength,false); // 设定进度条
Notification notification = builder.getNotification();
3.启动Notification
nm.notify(Notification_id, notification);