Notification,顾名思义,通知,就是我们常说的系统推送。

官网链接:http://developer.android.com/reference/android/app/Notification.html

要想使用Notification,还需要使用几个类,NotificationManagerNotificationCompat.BuilderPendingIntentIntent

这个是官网教你如何创建一个Notificiation:http://developer.android.com/training/notify-user/build-notification.html#action

根据官网的教程,练习创建一个Notification,并实现点击Notification跳转。

1.使用NotificationCompat.Builder类,创建一个Notification Builder。

NotificationCompat.Builder类位于support lib中的android.support.v4.app.NotificationCompat.Builder。继承自Object.

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)   //使用的是support.v4.app.NotificationCompat.Builder
mBuilder.setSmallIcon(R.drawable.notification_icon) //设置icon
mBuilder.setContentTitle("My notification") //设置标题Title
mBuilder.setContentText("Hello World!"); //设置内容

2.设置点击Notification的动作

 Intent resultIntent = new Intent(this, ResultActivity.class);                //使用Intent,设置跳转到ResultActivity
PendingIntent resultPendingIntent = PendingIntent.getActivity(this,0,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT); //使用PendingIntent
mBuilder.setContentIntent(resultPendingIntent); //
 Notification notification=mBuilder.build();  //获取真实的nofitication

3.发出通知

 int mNotificationId = 001;                                                   //设置Nofitication的ID
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //获取NotificationManager service实例
mNotifyMgr.notify(mNotificationId,notification); //构建一个Notification,并发出

以上就完成了一个Notication的显示和动作。

Android开发UI之Notification的更多相关文章

  1. Android开发--UI之Bundle的使用

    Android开发–UI之Bundle的使用 最近,把之前学过的东西大体的整理了以下,并且想把学过的心得分享给大家.我自己做了一个小小的demo,以便说明具体的应用. 这里的两个界面是通过第一个界面输 ...

  2. Android开发 UI布局

    Android开发 UI布局一.线性布局LinearLayout 什么是线性布局? 其实呢,线性布局就是把所有的孩子摆在同一条线上 <?xml version="1.0" e ...

  3. Android开发UI之开源项目第一篇——个性化控件(View)篇

    原文:http://blog.csdn.net/java886o/article/details/24355907 本文为那些不错的Android开源项目第一篇——个性化控件(View)篇,主要介绍A ...

  4. Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式

    前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...

  5. Android 开发UI牛博[转]

    Android 新兴的UI模式——侧边导航栏 侧边导航栏也就是大家熟知的SliddingMenu,英文也叫Fly-In App Menu.Side Navigation等.当然谷歌现在已经推出类似这个 ...

  6. Android开发UI之在子线程中更新UI

    转自第一行代码-Android Android是不允许在子线程中进行UI操作的.在子线程中去执行耗时操作,然后根据任务的执行结果来更新相应的UI控件,需要用到Android提供的异步消息处理机制. 代 ...

  7. Android开发UI之Action Bar

    郭大神的讲解:http://blog.csdn.net/guolin_blog/article/details/18234477 官网链接:http://developer.android.com/i ...

  8. Android开发UI之Toast的使用

    Toast,A toast provides simple feedback about an operation in a small popup. 对于操作提供一个简单反馈信息. 官网链接:htt ...

  9. Android开发手记(23) Notification

    有时候,我们需要应用程序在状态内显示一些通知信息,这时我们就需要使用Notification来完成这一工作.也许我们会想到以前经常使用的Toast来通知用户.虽然Notification与Toast都 ...

随机推荐

  1. 第十四篇、Ajax与Json

    1.Ajax的核心知识 1.1 XMLHttpRequest对象 function loadName(){ var xmlHttp; if(window.XMLHttpRequest){ xmlHtt ...

  2. Makefile当中宏定义传递字符串

    前几天遇到类似的问题[http://bbs.chinaunix.net/thread-1589386-1-1.html]: 在Makefile里面定义一个字符串在程序里面使用, CFLAGS += - ...

  3. day20 在php中通过php语句操作数据库

    第一步:连接数据库服务器 mysql_connect("数据库服务器地址","用户名","密码") 第二步:设定跟数据库打交道的网页的编码 ...

  4. mysql的1045解决方法

    mysql的连接方式有两种: UNIX域套接字连接,如: mysql -u root -p mysql -h localhost -u root -p TCP/IP套接字连接,如: mysql -h ...

  5. javascript正则表达式 —— RegExp 对象

    定义 RegExp RegExp 对象用于存储检索模式. 通过 new 关键词来定义 RegExp 对象.以下代码定义了名为 patt1 的 RegExp 对象,其模式是 "e": ...

  6. PHPCMS如何实现后台访问限制?

    修改phpcms 后台管理路径,可以有效的防止因为程序漏洞,或者是服务器安全问题所带来的 phpcms系统管理权限被黑客获取 文件路径:/caches/config/system.php 修改:'ad ...

  7. VC++2010添加菜单

    1  资源视图下面右键添加资源 选择menu 2  创建你想要的menu 3  找到CDialog::OnInitDialog();在后面添加代码. CMenu menu; menu.LoadMenu ...

  8. Linux操作命令(一)

    ls 命令 ls 命令是 linux 下最常用的命令,ls 命令就是 list 的缩写. ls 用来打印出当前目录的清单.如果 ls 指定其他目录,那么就会显示指定目录里的文件及文件夹清单. 通过 l ...

  9. JSP中pageEncoding和charset区别,中文乱码解决方案(转载)

    转载自:JSP中pageEncoding和charset区别,中文乱码解决方案 JSP指令标签中<%@ page contentType="text/html;charset=GB23 ...

  10. qt 5 小练习 创建无边框界面

    我们大家都知道QT5 自带的界面不是那么美观,并且每个软件我们都发现他们的边框是自定义的,所以我决定写一篇这样的博文,也许已经有许许多多篇大牛写的论文了,但我还是想写一篇记录自己的学习QT的历程 首先 ...