zoukankan      html  css  js  c++  java
  • Android笔记:通知

    可以在活动里创建,也可以在广播接收器里创建,还可以在服务里创建。

    NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

    创建一个Notification 对象就可以写成:
    Notification notification = new Notification(R.drawable.icon, "——————This is ticker text——————",System.currentTimeMillis());

                          图标                    刚出的时候一闪而过             创建的时间

    notification.setLatestEventInfo(context, "This is content title", "This iscontent text", null);

                         标题         正文

    manager.notify(1, notification);//数字表示ID,每个消息的ID应不同。

    PendingIntent主要提供了几个静态方法用于获取PendingIntent的实例,可以根据需求来选择是使用getActivity()方法、getBroadcast()方法、还是getService()方法。

    第一个参数是Context。第二个参数传入0 即可。第三个参数是一个Intent 对象,可以通过这个对象构建出PendingIntent 的“意图”。

    第四个参数用于确定PendingIntent 的行为,有FLAG_ONE_SHOT、FLAG_NO_CREATE、FLAG_CANCEL_CURRENT 和FLAG_UPDATE_CURRENT 这四种值可选。

    Intent intent = new Intent(this, NotificationActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_CANCEL_CURRENT);
    notification.setLatestEventInfo(this, "This is content title","This is content text", pi);//第四个参数是调用pendingintent的。

    NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    manager.cancel(1);//取消通知 “1"就是一开始传入的ID。

  • 相关阅读:
    caffe用到的命令和零碎知识
    Manjaro — ssh出现22端口拒绝访问问题(port 22: Connection refused)
    Linux 解压z01 .z02 .z03... zip分卷
    Manjaro_Windows双系统安装
    Linux 的chsh命令
    mat2json, python读取mat成字典, 保存json
    最便捷的caffe编译方法 ---- cmake+anaconda虚拟环境
    复制跳过软链接
    使用Screen解决ssh连接中断导致的训练中断问题
    Caffe训练时Loss=87.3365问题
  • 原文地址:https://www.cnblogs.com/lxwy1992/p/4745670.html
Copyright © 2011-2022 走看看