Notification的原生实现基本能够包括:java
使用getSystemService(context.Notification_service) 获取 Notificationmanager 的引用
ui
使用Notification Builder来构建 Notificationcode
使用前面 的 NotificationManager 启动Notificationget
简单逻辑代码以下:
it
获取NotificationManager的引用:
io
NotificationManager nm = (NotificationManager) mcontext.getSystemService(Context.NOTIFICATION_SERVICE);
2. 构建 Notification
class
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.启动Notificationservice
nm.notify(Notification_id, notification);