Android状态栏提醒——Notification
来源:互联网 发布:mac office 2011 卸载 编辑:程序博客网 时间:2024/06/05 17:34
//创建Builder对象
NotificationCompat.Builder builder=newNotificationCompat.Builder(MainActivity.this);
//进行相关设置
Bitmap bitmap =BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//设置大图标
builder.setLargeIcon(bitmap);
//设置小图标
builder.setSmallIcon(R.drawable.emo_im_angel);
//设置内容标题
builder.setContentTitle("放假通知");
//设置内容文本
builder.setContentText("从明天开始,放假10天,是不可能的");
//设置时间
builder.setWhen(System.currentTimeMillis()+1000000);
//设置info
builder.setContentInfo("1");
//设置通知是否在点击执行延迟意图时自动消失
builder.setAutoCancel(true);
//天加延迟意图---》点击通知的时候,进入SecondActivity
Intent intent=newIntent();
intent.setClass(MainActivity.this,SecondActivity.class);
PendingIntent pIntent=PendingIntent.getActivity(MainActivity.this,15, intent,PendingIntent.FLAG_UPDATE_CURRENT);
//给通知添加延迟意图
builder.setContentIntent(pIntent);
//获取NotificationManager对象
manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//发送通知 参数1通知id 参数2通知对象
manager.notify(10, builder.build());
}
/**取消通知的按钮的点击监听*/
publicvoid btnCancel(View view){
manager.cancel(10);
}
Notification notification =newNotification(R.drawable.ic_audio_notification,"哈哈,通知到来了",System.currentTimeMillis());
notification.flags =Notification.FLAG_AUTO_CANCEL;
//notification.sound =Uri.parse(uriString);
//五彩神灯 呼吸灯
notification.ledARGB =0xffffbb99;
notification.vibrate =newlong[]{100,200,100};
//设置通知对应的点击事件,进程间通讯,由另外一个应用程序执行的动作必须用PendingIntent 包装。
Intent intent =newIntent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel://110"));
PendingIntent contentIntent =PendingIntent.getActivity(this,0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this,"我是标题文本","我是标题的内容", contentIntent);
nm.notify(0, notification);
notification1.flags =Notification.FLAG_NO_CLEAR;
notification1.flags =Notification.FLAG_AUTO_CANCEL;
notification.sound =Uri.parse("");
notification.vibrate =newlong[]{100,200,100};
2.3设备必须设置setContentIntent
大视图通知:
三种样式:Inbox Style、Big picture style、Big Text Style
设置大视图样式:setStyle()
大视图样式类:Notification的内部类
Inbox Style:
Notification.InboxStyle
addLine(CharSequence cs)
Notification.InboxStyle
addLine(CharSequence cs)
Notification.InboxStyle
setSummaryText(CharSequence cs)
构造方法:
Notification.InboxStyle()
/** 按钮点击事件---》发送Inbox大视图通知 */
publicvoid btnClick(View view){
NotificationCompat.Builder builder =newNotificationCompat.Builder(
MainActivity.this);
// 设置
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("通知");
builder.setContentText("震动/声音");
// 声音
// builder.setDefaults(Notification.DEFAULT_SOUND);
// 震动
builder.setDefaults(Notification.DEFAULT_VIBRATE);
// InboxStyle样式对象
NotificationCompat.InboxStyle inboxStyle =newNotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle("InboxBig-ContentTile");
inboxStyle.setSummaryText("InboxBig-SummaryText");
for(int i =0; i <5; i++){
inboxStyle.addLine("第"+(i +1)+"项");
}
// 把Inbox样式设置给Builder
builder.setStyle(inboxStyle);
manager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(10, builder.build());
}
BigPicture
Notification.BigPictureStyle
bigLargeIcon(Bitmap b) //icon
Notification.BigPictureStyle
bigPicture(Bitmap b) //大图片
Notification.BigPictureStyle
setBigContentTitle(CharSequence title)
Notification.BigPictureStyle
setSummaryText(CharSequence cs)
构造方法
Notification.BigPictureStyle()
/** 按钮点击事件---》发送大图片视图通知 */
publicvoid btnBigPicture(View view){
NotificationCompat.Builder builder =newNotificationCompat.Builder(
MainActivity.this);
// 三项必设置
builder.setContentTitle("title");
builder.setContentText("contentText");
builder.setSmallIcon(R.drawable.ic_launcher);
// 大图片样式对象
NotificationCompat.BigPictureStyle bigPicture =newNotificationCompat.BigPictureStyle();
// //LargeIcon
// Bitmap bitmapL = BitmapFactory.decodeResource(getResources(),
// R.drawable.emo_im_money_mouth);
// Picture
Bitmap bitmapP =BitmapFactory.decodeResource(getResources(),
R.drawable.emo_im_angel);
// bigPicture.bigLargeIcon(bitmapL);
bigPicture.bigPicture(bitmapP);
bigPicture.setBigContentTitle("BigContentTitle");
bigPicture.setSummaryText("SummaryText");
// 设置大图片样式
builder.setStyle(bigPicture);
manager.notify(11, builder.build());
}
BigText:
构造方法:
Notification.BigTextStyle()
普通方法:
Notification.BigTextStyle
bigText(CharSequence cs)
Notification.BigTextStyle
setBigContentTitle(CharSequence title)
Notification.BigTextStyle
setSummaryText(CharSequence cs)
/** 按钮点击事件---》发送大文本视图通知 */
publicvoid btnBigTextClick(View view){
NotificationCompat.Builder builder =newNotificationCompat.Builder(
MainActivity.this);
// 三项必设置
// builder.setContentTitle("title");
builder.setContentText("contentText");
builder.setSmallIcon(R.drawable.ic_launcher);
// 大文本视图通知
NotificationCompat.BigTextStyle bigTextStyle =newNotificationCompat.BigTextStyle();
bigTextStyle
.bigText("钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃呃烦烦烦烦烦烦烦烦烦烦烦烦烦烦烦烦烦烦烦水水水水水水水水水水水水水水水水水水哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈笑嘻嘻谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢");
bigTextStyle.setBigContentTitle("BigContentTitle");
bigTextStyle.setSummaryText("SummaryText");
// 设置样式
builder.setStyle(bigTextStyle);
Notification notification = builder.build();
//不被清除
notification.flags=Notification.FLAG_NO_CLEAR;
manager.notify(12, notification);
}
- Android状态栏提醒——Notification
- android Notification 状态栏提醒
- Android状态栏提醒(Notification,NotificationManager)的使用!
- android 状态栏提醒 Notification 的使用!
- Android状态栏提醒--Notification的使用
- Android状态栏提醒(Notification,NotificationManager)的使用!
- android之状态栏提醒(Notification、NotificationManager)
- 状态栏提醒Notification,NotificationManager
- Android基础教程之---Android状态栏提醒(Notification,NotificationManager)的使用!
- Android基础教程之---Android状态栏提醒(Notification,NotificationManager)的使用!
- Android基础教程之---Android状态栏提醒(Notification,NotificationManager)的使用! .
- Android基础教程之---Android状态栏提醒(Notification,NotificationManager)的使用!
- Android基础教程之---Android状态栏提醒(Notification,NotificationManager)的使用!
- Android基础—Notification(状态栏通知)详解
- Android-用户提醒Notification
- android状态栏提醒
- Android--状态栏的图标和文字提醒/NotificationManager与Notification对象的应用
- Android 状态栏通知Notification
- 学习JAVA的真实感想
- hdoj 2191悼念512汶川大地震遇难同胞——珍惜现在,感恩生活【dp】
- swf文件解析(二) 文件分解及Tag获取
- LeetCode—137 Single Number II
- 词法分析器
- Android状态栏提醒——Notification
- 写单测,测试如何将N个case的代码简化为1个case的代码(重用和封装)
- 第四届山东省网络安全技能大赛 write up
- 数据结构基础:二叉树,堆,多叉树
- 需求:实现IOS翻页效果
- “互联网+”创新创业计划书(一)
- linux 下 .sh 文件语法
- 必懂java、android知识
- 杭电ACM1001