Notification通知栏的使用

一、基础的知识了解

    

    1.pendingIntent : 它是Intent的封装,可以跳转某个Activity、给Service发送一个命令、还可以发送一个广播

     

    2.进度条的使用方法

    

    3.更新通知栏的信息

    

二、代码的编写

  public void showNotification(FileInfo fileInfo) {

   containsKey这个是Map函数是否包含你要写入的键值对的关键字
    //if(mNotifications.containsKey())


  //创建Notification的对象
Notification mNotification = new Notification();
//设置滚动文字
mNotification.tickerText = "开始下载";
//设置当前时间
mNotification.when = System.currentTimeMillis();
//设置图标
mNotification.icon = R.drawable.ic_launcher_background;
//设置通知属性(用户点击完之后会自动消失)
mNotification.flags = Notification.FLAG_AUTO_CANCEL;
//设置contentIntent通知方式
Intent intent = new Intent(mContext, MainActivity.class);

  //
PendingIntent将Intent包装起来的函数
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
   mNotification.contentIntent = pendingIntent;
}
原文地址:https://www.cnblogs.com/liunx1109/p/9761072.html