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。

  • 相关阅读:
    LeetCode 647. Palindromic Substrings
    jquery--find与children方法的区别
    JavaScript MVC框架PK:Angular、Backbone、CanJS与Ember
    javascript之原型prototype
    js的数据格式之json
    Javascript:必须知道的Javascript知识点之“单线程事件驱动”
    javascript自我测试题
    javascript:delete 删除对象的属性
    javascript:function 函数声明和函数表达式 详解
    [转]JavaScript可否多线程? 深入理解JavaScript定时机制
  • 原文地址:https://www.cnblogs.com/lxwy1992/p/4745670.html
Copyright © 2011-2022 走看看