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。

  • 相关阅读:
    怎样提高js的编程能力
    如何提升自己
    利用nginx做反向代理解决前端跨域问题
    vue项目中使用组件化开发
    vue中refs的使用
    vue项目使用keep-alive的作用
    hadoop安装、使用过程的异常汇总
    CSS选择器优先级总结
    为什么CSS选择器是从右往左解析
    MySql中游标的定义与使用方式
  • 原文地址:https://www.cnblogs.com/lxwy1992/p/4745670.html
Copyright © 2011-2022 走看看