private static final int NOTIFICATION_ID=250;  //用来标示notification,通过notificatinomanager来发布同样标示的notification将更新旧的通知,同时取消notification也需要这个标示(android很多地方都用到标示这么一个玩意)
  
private void setNotification(String note) {
     //获取系统通知服务
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.icon = R.drawable.notify; //通知图标,官方文档中说必须有icon才能显示出notification
notification.when = System.currentTimeMillis();
notification.tickerText = note; //通知出现在标题栏时显示的内容
notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻Flag
notification.defaults = Notification.DEFAULT_SOUND; //设置notification的提示音为系统默认提示声音
notification.setLatestEventInfo(this, "提示消息", note, null);
notificationManager.notify(NOTIFICATION_ID, notification);
} // 取消通知
private void cancelNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
}

添加常驻Notification的更多相关文章

  1. Android 添加常驻图标到状态栏

    / * * 如果没有从状态栏中删除ICON,且继续调用addIconToStatusbar,则不会有任何变化.如果将notification中的resId设置不同的图标,则会显示不同的图标 * / p ...

  2. android Notification介绍

    如果要添加一个Notification,可以按照以下几个步骤 1:获取NotificationManager: NotificationManager m_NotificationManager=(N ...

  3. Android之Notification介绍

    Notification就是在桌面的状态通知栏.这主要涉及三个主要类: Notification:设置通知的各个属性. NotificationManager:负责发送通知和取消通知 Notifica ...

  4. Notification NotificationManager RemoteViews PendingIntent

    Notification和NotificationManager :可以用来实现可视化的消息通知等,比如:下载进度显示,消息显示,广播的内容等 RemoteViews :用于创建自定义的Notific ...

  5. Android中的消息通知(NotificationManager和Notification)

    下面来谈谈notification,这个notification一般用在电话,短 信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这 ...

  6. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

  7. android学习日记21--消息提示之Toast和Notification

    1.Toast Toast译为土司,类似切片面包,用于弹出比较快速的及时提示信息.当Toast被显示时,虽然它悬浮应用程序最上方,但是并未获得焦点.它的设计就是为了提示有用的信息,而不打扰用户其他操作 ...

  8. Notification使用以及PendingIntent.getActivity() (转)

    public void sendNotification(Context ctx,String message) { //get the notification manager String ns ...

  9. Android Notification通知详细解释

    Android Notification通知具体解释  Notification: (一).简单介绍:         显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...

随机推荐

  1. spi驱动无法建立spidev问题

    参考这里: http://e2e.ti.com/support/arm/sitara_arm/f/791/t/168122.aspx http://communistcode.co.uk/blog/b ...

  2. MapReduce从输入文件到Mapper处理之间的过程

    1.MapReduce代码入口 FileInputFormat.setInputPaths(job, new Path(input)); //设置MapReduce输入格式 job.waitForCo ...

  3. MFC学习 序列化

    void CArchiveView::OnWrite() { // Archive就是可序列化的类, 要头文件中DECLARE_DYNCREATE(CArchiveDoc) // 重写 virtual ...

  4. 用FireBreath制作浏览器插件

    参考: http://blog.csdn.net/z6482/article/details/7486921 1.下载firebreath, 安装cmake, python. 2.在FireBreat ...

  5. 第一课 opengl简介

    1. 什么是opengl: opengl是图形硬件的一种软件接口. 2. opengl对场景中的图像进行渲染时所执行的主要图形操作 1)根据几何图元创建形状,从而建立物体的数学描述. 2)在三维空间中 ...

  6. university, school, college, department, institute的区别

    这些个词没有太大区别,有时候有些词是可以通用的,而有些用法则是随着地域时间的不同而变迁. 一般说来,college译作“学院”,它是university (综合性大学)的一个组成部分,例如,一所综合大 ...

  7. 【LeetCode】21. Merge Two Sorted Lists

    题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  8. EXT学习之——Extjs 文本框 TextField 添加点击(onclick)事件方法

    { xtype:'textfield', listeners: { render: function(p) { // Append the Panel to the click handler's a ...

  9. Sass基础语法

    Sass是CSS3语言的扩展,在CSS的基础之上添加了新特性和语法,能省事地写出更好的样式表.Sass引擎是基于Ruby的. 导入Sass文件: @import "colors" ...

  10. Cordova V3.0.0中config.xml配置文件的iOS Configuration

    http://www.cnblogs.com/lovecode/articles/3305655.html   轉載這個 <preference> 关于这个标签的可用设置有: Disall ...