笔记 android发送状态栏消息
2016-03-31 16:30
459 查看
编程环境android4.4+eclipse
定义
NotificationManager manager;
NotificationCompat.Builder notifyBuilder;
在onCreate中
/* 实例化NotificationManager以获取系统服务 */
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
使用
notifyBuilder = new NotificationCompat.Builder(this)
/* 设置small icon */
.setSmallIcon(R.drawable.ic_launcher)
/* 设置title */
.setContentTitle("打卡")
/* 设置详细文本 */
.setContentText(item.title).setTicker("足迹消息")
/* 设置点击后通知消失 */
.setAutoCancel(true)
/* 意图 点击跳转到SignActivity */
.setContentIntent(pendingIntent);
abc_id++;
manager.notify(100 * abc_id, notifyBuilder.build());
setContentIntent(pendingIntent);
意图 可使用也可不使用,使用需定义下
// 点击的意图ACTION是跳转到Intent
Intent resultIntent = new Intent(this, SignActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
修改后
NotificationManager notificationManager;
NotificationCompat.Builder nb;
String svcName = Context.NOTIFICATION_SERVICE;
notificationManager = (NotificationManager) getSystemService(svcName);
nb = new Builder(this);
使用
nb2.setSmallIcon(R.drawable.ic_launcher).setContentTitle("标题")
.setWhen(System.currentTimeMillis())
.setContentText("内容内容内容"+ncc).setAutoCancel(true).setContentInfo("info");
ncc++;
notificationManager.notify(ncc, nb2.build());
解释:
状态栏消息
示例
**** 标题 21:12
**** 内容内容内容"+ncc info
****
星号是图片区域
setSmallIcon 设置图标
setContentTitle 设置示例中的标题部分
setContentText 设置示例中的内容部分
setContentInfo 设置示例中时间下面的info部分
setAutoCancel 设置消息是否可以被点击取消(被单击后自动取消自己)
setWhen 设置展开的状态栏按时间顺序排序通知
定义
NotificationManager manager;
NotificationCompat.Builder notifyBuilder;
在onCreate中
/* 实例化NotificationManager以获取系统服务 */
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
使用
notifyBuilder = new NotificationCompat.Builder(this)
/* 设置small icon */
.setSmallIcon(R.drawable.ic_launcher)
/* 设置title */
.setContentTitle("打卡")
/* 设置详细文本 */
.setContentText(item.title).setTicker("足迹消息")
/* 设置点击后通知消失 */
.setAutoCancel(true)
/* 意图 点击跳转到SignActivity */
.setContentIntent(pendingIntent);
abc_id++;
manager.notify(100 * abc_id, notifyBuilder.build());
setContentIntent(pendingIntent);
意图 可使用也可不使用,使用需定义下
// 点击的意图ACTION是跳转到Intent
Intent resultIntent = new Intent(this, SignActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
修改后
NotificationManager notificationManager;
NotificationCompat.Builder nb;
String svcName = Context.NOTIFICATION_SERVICE;
notificationManager = (NotificationManager) getSystemService(svcName);
nb = new Builder(this);
使用
nb2.setSmallIcon(R.drawable.ic_launcher).setContentTitle("标题")
.setWhen(System.currentTimeMillis())
.setContentText("内容内容内容"+ncc).setAutoCancel(true).setContentInfo("info");
ncc++;
notificationManager.notify(ncc, nb2.build());
解释:
状态栏消息
示例
**** 标题 21:12
**** 内容内容内容"+ncc info
****
星号是图片区域
setSmallIcon 设置图标
setContentTitle 设置示例中的标题部分
setContentText 设置示例中的内容部分
setContentInfo 设置示例中时间下面的info部分
setAutoCancel 设置消息是否可以被点击取消(被单击后自动取消自己)
setWhen 设置展开的状态栏按时间顺序排序通知
相关文章推荐
- Android Stutio设置注释模板
- 笔记 Android动画
- Android EditText清除光标
- android textview字符串指定分段设置字体颜色
- Android 中Activity、Window和View之间的关系
- Android Glide Google 推荐加载图片框架(加载图片详解篇)
- Android Studio使用经验汇总
- Android实现调度任务的三种方式:TimerTask、ScheduledExecutorService、Handler
- android-自定义View解决wrap_content无效的问题
- Android Dalvak虚拟机内存回收规则
- android 真机调试
- Android开发学习笔记:数据存取之SQLite浅析
- java Android 中的字符串比较和double类型转换为两位小数点
- Android TextView系列--第一篇
- android 启动报错
- Android 蓝牙开发基本流程
- 重温android studio jni编译生成so文件
- Android Intent.FLAG_NEW_TASK详解,包括其他的标记的一些解释
- Android AsynTask源码分析和优缺点
- Android MVP设计的简单理解