安卓状态栏通知Status Bar Notification
安卓系统通知用户三种方式:
1.Toast Notification
2.Dialog Notification
3.Status Bar Notification Status Bar Notification,状态栏通知
发送一个状态栏通知必须用到两个类:NotificationManager,Notification
1.NotificationManager是一个系统Service,必须通过getSystemService()获取
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
2.Notification是具体的状态栏通知对象
调用NotificationManager的notify()方法创建Notification
两部分:
①:状态栏通知
notification.icon=R.drawable.ic_launcher;
notification.tickerText="My First Notification";
notification.when=System.currentTimeMillis();
②:下拉通知列表和点击跳转:
两种方式:
一:setLatestEventInfo()方法
Context context = getApplicationContext();
CharSequence contentTitle="Notification";
CharSequence contentText="Notification Context";
Intent intent=new Intent(Main.this,Turn.class);
PendingIntent pendingIntent=PendingIntent.getActivity(Main.this, 0, intent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
二:自定义通知栏
notification.flags=Notification.FLAG_AUTO_CANCEL;用户点击后通知自动取消
设置两个变量contentView和contentIntent
RemoteViews contenView=new RemoteViews(getPackageName(), R.layout.notification_layout);
contenView.setImageViewResource(R.id.icon, R.drawable.ic_launcher);
contenView.setTextViewText(R.id.contentText, "自定义通知");
notification.contentView=contenView;
Intent intent1=new Intent(Main.this,Turn.class);
PendingIntent pendingIntent1=PendingIntent.getActivity(Main.this, 0, intent1, 0);
notification.contentIntent=pendingIntent1;
Tips:
可能遇到的错误:Couldn't expand RemoteViews for:
检查是否是RemoteViews对应的layout里使用了它不支持的组件
检查RemoteViews对应的layout布局文件是否有基本错误,例如忘记声明宽高等
安卓状态栏通知Status Bar Notification的更多相关文章
- Material Design 之 定义状态栏(Status Bar)的颜色
Hey,好久不见.今天遇到一个问题,想要把Status Bar 和 Tool Bar的颜色弄成一样的,或者是类似的,例如Material Design: 图中Status Bar颜色比Tool Bar ...
- iOS7 设置隐藏状态栏(status bar)
在info.plist 添加 UIViewControllerBasedStatusBarAppearance(View controller-based status bar appearance) ...
- IQKeyboardManager 状态栏(status bar)问题
因为懒,所以具体什么样子,参考下面的链接 具体的问题情况参考:StatusBar background problem #1158 我解决的思路很简单,就是在监听键盘消失的时候,去设置 statys ...
- 【Android】状态栏通知Notification、NotificationManager详解(转)
在Android系统中,发一个状态栏通知还是很方便的.下面我们就来看一下,怎么发送状态栏通知,状态栏通知又有哪些参数可以设置? 首先,发送一个状态栏通知必须用到两个类: NotificationMa ...
- Android的状态栏通知(Notification)
通知用于在状态栏显示消息,消息到来时以图标方式表示,如下: 如果需要查看消息,可以拖动状态栏到屏幕下方即可查看消息. 1.Layout布局文件: <RelativeLayout xmlns:an ...
- Java基础之扩展GUI——添加状态栏(Sketcher 1 with a status bar)
控制台程序. 为了显示各个应用程序参数的状态,并且将各个参数显示在各自的面板中,在应用程序窗口的底部添加状态栏是常见且非常方便的方式. 定义状态栏时没有Swing类可用,所以必须自己建立StatusB ...
- 状态栏通知Notification的简单使用
今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...
- Android 状态栏通知Notification、NotificationManager简介
Notification(通知)一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个通知: 在Android系统中, ...
- Android - 隐藏最顶端的通知条(Top Notification Bar)
隐藏最顶端的通知条(Top Notification Bar/ActionBar) 本文地址: http://blog.csdn.net/caroline_wendy Android中, 视频播放等功 ...
随机推荐
- SqlServer跨域查询
SELECT * FROM OPENDATASOURCE('SQLOLEDB','Data Source=192.168.1.14;User ID=sa;Password=sql.com').eBui ...
- SVN 密码破解,svn密码本地找回 忘记密码
svn 密码被保存在本地文件中 C:\Users\[your computer name]\AppData\Roaming\Subversion\auth\svn.simple 文件下. 加密保存 到 ...
- C3P0连接池配置方式
c3p0的配置方式分为三种,分别是 1.setters一个个地设置各个配置项 2.类路径下提供一个c3p0.properties文件 3.类路径下提供一个c3p0-config.xml文件 1.set ...
- Codeforces Round #278 (Div. 1)
A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...
- CSS阻止文本选择
在日常运用中,经常遇到点击按钮/菜单的时候,选中了文本,为了避免这种情况,可以使用纯css来解决这个问题(IE10+),对于旧版本的就只能用js:onselectstart = 'return fal ...
- python中的super
super用于类的继承.用super()代替父类名 (一)通过类名调用父类中的方法 (二 ...
- GO逆转字符串
package main import "fmt" func main(){ str:="foobar" a:=[]rune(str) ,len(a)-;i&l ...
- tomcat文件夹与文件解析
今天看到一篇不错的文章,如下: /bin:存放启动和关闭tomcat的脚本文件: /conf:存放tomcat的各种配置文件,比如:server.xml/ server/lib:存放tomcat服务器 ...
- 基于异步的MVC webAPI控制器
MVC – Task-based Asynchronous Pattern (TAP) – Async Controller and SessionLess Controller Leave a re ...
- 有关WCF的契约问题
WCF中的契约包括4种 数据契约 DataContract ->DataMember 服务契约 ServiceContract-> OperactionContract 消息契约 Mess ...