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. win10 删除资源管理器中的6个文件夹

    细心的朋友会发现,在Win10此电脑(计算机)中,除了我们最熟悉的磁盘外,还新增了视频.图片.文档.下载.音乐.桌面这6个文件夹.不少网友举觉得这6个文件夹其实并没什么用,想要去除删掉.那么Win10 ...

  2. [译]Autoprefixer:用最可行的方式处理浏览器前缀的CSS后处理器

    Autoprefixer,通过Can I Use数据库来确定哪些浏览器前缀是需要的,然后解析CSS文件,将前缀添加到CSS规则里. 你所要做的就是添加你的资源构建工具(比如:Grunt),然后你就可以 ...

  3. MVC异步 导入excel文件

    View页面 js文件.封装到一个js文件里面 (function ($) { //可以忽略 var defaultSettings = { url: "http://upload.zhtx ...

  4. 九度OJ 1104 整除问题

    题目地址:http://ac.jobdu.com/problem.php?pid=1104 题目描述: 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除. 输入: 两个整数n(2 ...

  5. debian 学习记录-2 -账户 -关机

    linux考虑系统安全设定了root账号和user账号 权限较低的user账号下,连关机命令都执行不了…… 用户切换... 用户切换1 命令su(在user账号下,即可开启root账号模式) 用户切换 ...

  6. centos7下添加win7引导

    这次在centos7下添加为win7引导的过程可谓是一波三折,首先是在网上找教程,这个过程还是很顺利的,通不断的 搜索,找到了两个办法.第一个办法就是在root下执行这样的一个命令: grub2-mk ...

  7. 动态链接库找不到 : error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory

    问题: 运行gsl(GNU scientific Library)的函数库,用 gcc erf.c -I/usr/local/include -L/usr/local/lib64 -L/usr/loc ...

  8. jQuery Mobile里xxx怎么用呀?(缓存篇)

    jQuery Mobile初始页面DOM Cache所引发的问题 HTML元素事件多次触发: jsFiddle: http://jsfiddle.net/gn9JA/2/ cause: 在jsFidd ...

  9. mac下如何查看指定端口被谁占用并且杀死该进程

    在本地部署 Web 应用时我有遇到过某网络端口已经被其他程序占用的情况,这时候就需要先退出占用该端口的进程,我们可以通过“终端”来实现结束占用某特定端口的进程 1.打开终端,使用如下命令: lsof ...

  10. CSS 之 @media

    @media 版本:CSS2 兼容性:IE5+ 语法: @media  sMedia  {sRules} 取值: sMedia : 指定设备名称.请参阅设备类型 all, aural, braille ...