实现Android的消息通知栏
来源:互联网 发布:cloudstack 网络 编辑:程序博客网 时间:2024/05/17 22:25
背景知识:可以用Activity和Service来开始消息通知,两者的区别在于一个是在前台触发,一个是后台服务触发。
要使用消息通知,必须要用到两个类:NotificationManager和Notification,其他NotificationManager的初始化是用getSystemService方法,并且通过notify方法来向android系统发送消息栏通知和显示。
效果 :
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//消息通知栏
//定义NotificationManager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
//定义通知栏展现的内容信息
int
icon = R.drawable.icon;
CharSequence tickerText =
"我的通知栏标题"
;
long
when = System.currentTimeMillis();
Notification notification =
new
Notification(icon, tickerText, when);
//定义下拉通知栏时要展现的内容信息
Context context = getApplicationContext();
CharSequence contentTitle =
"我的通知栏标展开标题"
;
CharSequence contentText =
"我的通知栏展开详细内容"
;
Intent notificationIntent =
new
Intent(
this
, BootStartDemo.
class
);
PendingIntent contentIntent = PendingIntent.getActivity(
this
,
0
,
notificationIntent,
0
);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
//用mNotificationManager的notify方法通知用户生成标题栏消息通知
mNotificationManager.notify(
1
, notification);
- 实现Android的消息通知栏
- 实现Android的消息通知栏
- 实现Android的消息通知栏
- 实现Android的消息通知栏
- 实现Android的消息通知栏
- Android应用消息通知栏的实现
- Notification消息通知 通知栏的实现
- android通知栏的消息通知(Notification)
- android的消息通知栏
- SignalR+HTML5实现消息推送及Android通知栏消息
- Android实现google消息通知
- Android 通知栏消息
- Android 通知栏消息
- android 通知栏消息
- Notification消息栏通知的实现
- Android简单的消息通知栏
- Google Firebase 消息通知 android + nodejs 以及.net的实现
- android 通知栏的实现
- 【Unity3d开发相关】小地图高速创建
- 黑马程序员——JAVA基础之数据类型
- Service联合Broadcase更新UI
- vs2012编译boost_1_54_0
- Linux内存管理(上)
- 实现Android的消息通知栏
- JAVA的日期应用:Date、DateFormat、Calendar
- 数学问题--大数的阶乘
- 题目1504:把数组排成最小的数-PAT
- 手机游戏制作(开发流程)
- opencv配置方法
- Linux内存管理(下)
- HttpClient和HttpGet 设置参数的优先级
- 百度网站诚信认证现在是个什么情况呢?