Notification 的进度条 简单展现

Notification的原生实现基本能够包括:java

  1. 使用getSystemService(context.Notification_service) 获取 Notificationmanager 的引用
    ui

  2. 使用Notification Builder来构建 Notificationcode

  3. 使用前面 的 NotificationManager 启动Notificationget

简单逻辑代码以下:
it

  1. 获取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);
相关文章
相关标签/搜索