短信来了,手机会发出震动或者声音通知,同时在手机上面会显示带图标的提示信息,这就是手机上的提示功能,同样地,在Android的开发中,也为我们提供了提示的相应接口。本文就将对Android中提示服务Notification做下讲解。

这里我们通过分析一个Notification的具体实现过程来,来了解Notification服务是如何实现和取消的。

A、首先需要获取系统Notification服务

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

B、创建Notification,参数为别为图标、提示标题、提示时间

Notification notification = new Notification(R.drawable.n,"即兴提示!",System.currentTimeMillis());

C、创建意图Intent并转化为非即时意图,这样就可以在任何不确定时间被执行

Intent intent = new Intent(this,NewActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,intent,0);

D、设置Notification标题、内容和触发事件

notification.setLatestEventInfo(this, "ATAAW.COM", "即兴时代!", contentIntent);

E、开启提示

notificationManager.notify(1,notification);

F、取消提示

notificationManager.cancel(1);

Android中的提示服务如上所示,当开启Notification的时候,提示信息就会显示在手机上,并在手机状态栏上有一个图标显示着,当点击这个提示就会触发事件,这时会开启NewActivity,而通过提示服务的calcel方法则可以取消提示。

更多相关文章

  1. Android Market中产品图标设计原则
  2. Android图标设计标准和原则
  3. Android消息提示框和对话框的使用
  4. Android核心分析 --分析方法论探讨之设计意图
  5. Android安卓系统提示应用程序未安装的解决方法
  6. Android 中的(意图Intent)机制,常见应用
  7. 【转】Android -- 探究Android的多分辨率支持以及各种类型图标尺
  8. Android 如何在Launcher桌面创建或者删除快捷图标
  9. Android 常用的提示框Dialog

随机推荐

  1. 【Android】Android Clean Architecture
  2. Android OpenGL例子学习
  3. Android使用百度地图SDK获得当前设备位置
  4. Android逆向分析常用网站
  5. Linux系统Android SDK 下载版本,报错Warni
  6. android(2.0以后版本) 中读取联系人和通
  7. 更新SDK后eclipse报错This Android SDK r
  8. Android中常用的Intent.Action整理
  9. android 常用JVM配置参数
  10. webView去掉右侧导航条