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都 ...
随机推荐
- POJ 2777(线段树)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42507 Accepted: 12856 Des ...
- 客户调用COM流程
参考:COM技术内幕 DllGetClassObjecthttps://msdn.microsoft.com/en-us/library/windows/desktop/ms680760.aspx ...
- VS2010 error RC2135: file not found
VS2010 C++ win32 DLL 工程, 添加 rc 文件, 编辑 String Table. 默认情况下英文版本的 rc 文件能够顺序编译通过,为了让工程支持多语言,将字符串修改为其他语言时 ...
- JSTL之迭代标签库
JSTL之迭代标签库 JSTL的全称是 Java Server Pages Standard Tag Library,翻译过来就是JSP标准标签库,它包含了在开发JSP页面时经常用到的一组标准标签.这 ...
- <<深入Java虚拟机>>-第三章-垃圾收集器与内存分配策略-学习笔记
垃圾收集 垃圾收集(Garbage Collection,GC),垃圾收集需要完成的三件事情. 哪些对象需要回收 什么时候回收 如何回收 如何确定对象已死(即不可能在被任何途径引用的对象) 引用计数算 ...
- jQuery关于导航条背景切换
效果如下: <DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jqu ...
- Memcache存储大数据的问题
Memcached存储单个item最大数据是在1MB内,假设数据超过1M,存取set和get是都是返回false,并且引起性能的问题. 我们之前对排行榜的数据进行缓存,因为排行榜在我们全部sql se ...
- 【转】C#.net拖拽实现获得文件路径
C#.net拖拽实现获得文件路径 作者Attilax , EMAIL:1466519819@qq.com 思路: 通过DragEnter事件获得被拖入窗口的“信息”(可以是若干文件,一些文字等等), ...
- PS初始化配置
前端工程师在使用photoshop之前需要进行一些初始化设置,主要包括以下3个 [1]首选项设置 <ctrl+k> 编辑 > 首选项 > 单位与标尺 > 把标尺和文字的单 ...
- [Linux]查看本机IP
命令: ~$ ip addr showor~$ ipconfig