Android开发UI之Notification
Notification,顾名思义,通知,就是我们常说的系统推送。
官网链接:http://developer.android.com/reference/android/app/Notification.html
要想使用Notification,还需要使用几个类,NotificationManager、NotificationCompat.Builder、PendingIntent、Intent
这个是官网教你如何创建一个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的更多相关文章
- Android开发--UI之Bundle的使用
Android开发–UI之Bundle的使用 最近,把之前学过的东西大体的整理了以下,并且想把学过的心得分享给大家.我自己做了一个小小的demo,以便说明具体的应用. 这里的两个界面是通过第一个界面输 ...
- Android开发 UI布局
Android开发 UI布局一.线性布局LinearLayout 什么是线性布局? 其实呢,线性布局就是把所有的孩子摆在同一条线上 <?xml version="1.0" e ...
- Android开发UI之开源项目第一篇——个性化控件(View)篇
原文:http://blog.csdn.net/java886o/article/details/24355907 本文为那些不错的Android开源项目第一篇——个性化控件(View)篇,主要介绍A ...
- Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式
前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...
- Android 开发UI牛博[转]
Android 新兴的UI模式——侧边导航栏 侧边导航栏也就是大家熟知的SliddingMenu,英文也叫Fly-In App Menu.Side Navigation等.当然谷歌现在已经推出类似这个 ...
- Android开发UI之在子线程中更新UI
转自第一行代码-Android Android是不允许在子线程中进行UI操作的.在子线程中去执行耗时操作,然后根据任务的执行结果来更新相应的UI控件,需要用到Android提供的异步消息处理机制. 代 ...
- Android开发UI之Action Bar
郭大神的讲解:http://blog.csdn.net/guolin_blog/article/details/18234477 官网链接:http://developer.android.com/i ...
- Android开发UI之Toast的使用
Toast,A toast provides simple feedback about an operation in a small popup. 对于操作提供一个简单反馈信息. 官网链接:htt ...
- Android开发手记(23) Notification
有时候,我们需要应用程序在状态内显示一些通知信息,这时我们就需要使用Notification来完成这一工作.也许我们会想到以前经常使用的Toast来通知用户.虽然Notification与Toast都 ...
随机推荐
- ios常用的一些类库
在网上收集到的 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https:/ ...
- 代理的使用 一(helloworld级别)
个人理解(估计,半年一年后,在看到这篇文章的时候,会觉得,当时真的弱爆了) 当我们自定义view的时候,比如说view上面有几个按钮,那么我们在别的地方使用这个view的时候,怎么来处理这些点击事件呢 ...
- this 关键字
导读 本文将列举C#中this关键字的用途 1.this 含义 2.用this 关键字避免参数与字段的混淆 3.用this关键字串联构造器 4.索引器 6.Visitor 模式 this 含义 C# ...
- C语言文件读写
1.用fopen打开文件 该函数的原型为FILE *fopen(const char *filename, const char *mode),第一个参数是文件名,第二个参数是打开文件的模式. 打开文 ...
- LA 2965 Jurassic Remains (中途相遇法)
Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...
- ImageButton如何让图片按比例缩放不被拉伸
了解 在安卓的界面XML中,ImageButton有这样一个属性android:scaleType,他干嘛的? ImageView的Scaletype决定了图片在View上显示时的样子,如进行何种比例 ...
- OpenJudge/Poj 2000 Gold Coins
1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...
- 浅谈MVC、MVP、MVVM架构模式的区别和联系
MVC.MVP.MVVM这些模式是为了解决开发过程中的实际问题而提出来的,目前作为主流的几种架构模式而被广泛使用. 一.MVC(Model-View-Controller) MVC是比较直观的架构模式 ...
- WPF MVVM 用户控件完成分页
项目中经常会有分页查询的情况,在WPF中我们可以通过用户控件完成分页 一下为分页控件的页面代码, <UserControl x:Class="Foundation.UCtrl.Next ...
- Activity组件
Activity 间书作者:阿敏其人 关于Activity博文上 间书作者:阿敏其人 关于Activity博文中 间书作者:阿敏其人 关于Activity博文下