NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);Notification notification = new Notification(android.R.drawable.btn_default, "新的通知", System.currentTimeMillis());     // 通过构造函数设定通知的图标与标题Intent intentNoti = new Intent(Intent.ACTION_VIEW);    // 可以使用其他的意图,以实现希望的功能PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intentNoti, 0);notification.setLatestEventInfo(getApplicationContext(), "通知的标题", "通知的内容", contentIntent);    // 设定通知的标题与内容,超出一行的部分将被省略notificationManager.notify(notificationID, notification);   // 生成 ID 为 notificationID 的通知。若该 ID 已存在,则更新已有通知的内容

 

说明:NotificationManager 可以通过 getSystemService(NOTIFICATION_SERVICE) 方法取得。它本身还有一些其他的便利方法:cancel(int id)删除指定 id 的通知。cancelAll()删除本应用程序发出的所有通知。

更多相关文章

  1. android 入门demo 事件监听
  2. android 状态栏显示运行图标
  3. Android文件读写
  4. First Preview of Android(安卓)N: Developer APIs & Tools
  5. android 对话框
  6. Android定义一个不消失的悬停通知栏
  7. android、pull解析xml
  8. Android消息通知声音和振动
  9. APP启动时白屏或出现标题

随机推荐

  1. android加载大量图片内存溢出的三种解决
  2. android apk dex odex jar 等文件的 反编
  3. android 监听添加或者删除应用
  4. Android常用工具整理
  5. Android中实现物体在屏幕的移动
  6. 安卓开发ScrollView嵌套ListView只显示一
  7. android 中文api (62) ―― ViewSwitcher
  8. Android滚动显示数字动画
  9. android自学笔记《二》——开发环境的搭
  10. android(11)_文件操作读取模式