android笔记16-Notification
来源:互联网 发布:linux c程序编译 编辑:程序博客网 时间:2024/06/08 08:05
Notification:状态栏通知;
通知栏的内容:
图标,标题,内容,时间,点击后的响应;
Notification.Builder的方法:
setSmallIcon(R.drawable...):设置图标; setTicker(string):设置手机状态栏的提示;
setWhen(System.currentTimeMillis()):时间;
setContentTitle(String):设置标题;
setContentText(String):设置通知内容;
setContenIntent(PendingIntent):设置点击响应;
setDefaults(Notification.DEFAULT_SOUND):设置提示声音,Notification.DEFAULT_LIGHTS:设置指示灯,Notification.DEFAULT_VIBRATE:设置震动效果;Notification.DEFAULT_ALL:包括以上三种;
注意设置指示灯或震动效果时都需要权限:
在Manifest的permission中:android.permission.FLASHLIGHT--指示灯;
android.permission.VIBRATE--震动;
实现通知栏需要两个类:
通知管理类,通知类;
设置通知参数步骤:
第一步:创建Builder对象(是notification的builder)并new出Notification.Builder(this),通过调用builder的方法来设置,setSmallIcon(R.drawable...),setTicker...;
第二步(点击后的响应):创建PendingIntent对象并赋值为PendingIntent.getActivity(context,requestCode,intent,flags):
context:this;
requestCode:请求码,0;
intent:创建Intent对象,在new中根据需求选择构造的类.class;
flags--0;
第三步:创建Notification对象,并将builder.build()赋值//4.1即以上,要用builder.build()方法,以下要用builder.getNotification()方法;
第四步:创建NotificationManager对象,因为是系统的常用服务,赋值为getSystemService(Context.NOTIFICATION_SERVICE),需强制转化;调用成员函数notify(id,notification)来加载Notification,id是一个int值,表示notification的id,自行赋值即可;
取消通知:
调用manager.cancle(id);id为diaoyongnotify函数时,填入的id;
通知栏的内容:
图标,标题,内容,时间,点击后的响应;
Notification.Builder的方法:
setSmallIcon(R.drawable...):设置图标; setTicker(string):设置手机状态栏的提示;
setWhen(System.currentTimeMillis()):时间;
setContentTitle(String):设置标题;
setContentText(String):设置通知内容;
setContenIntent(PendingIntent):设置点击响应;
setDefaults(Notification.DEFAULT_SOUND):设置提示声音,Notification.DEFAULT_LIGHTS:设置指示灯,Notification.DEFAULT_VIBRATE:设置震动效果;Notification.DEFAULT_ALL:包括以上三种;
注意设置指示灯或震动效果时都需要权限:
在Manifest的permission中:android.permission.FLASHLIGHT--指示灯;
android.permission.VIBRATE--震动;
实现通知栏需要两个类:
通知管理类,通知类;
设置通知参数步骤:
第一步:创建Builder对象(是notification的builder)并new出Notification.Builder(this),通过调用builder的方法来设置,setSmallIcon(R.drawable...),setTicker...;
第二步(点击后的响应):创建PendingIntent对象并赋值为PendingIntent.getActivity(context,requestCode,intent,flags):
context:this;
requestCode:请求码,0;
intent:创建Intent对象,在new中根据需求选择构造的类.class;
flags--0;
第三步:创建Notification对象,并将builder.build()赋值//4.1即以上,要用builder.build()方法,以下要用builder.getNotification()方法;
第四步:创建NotificationManager对象,因为是系统的常用服务,赋值为getSystemService(Context.NOTIFICATION_SERVICE),需强制转化;调用成员函数notify(id,notification)来加载Notification,id是一个int值,表示notification的id,自行赋值即可;
取消通知:
调用manager.cancle(id);id为diaoyongnotify函数时,填入的id;
0 0
- android笔记16-Notification
- Android笔记--Notification
- Android笔记 notification
- android学习笔记35:notification
- android基础笔记:notification通知
- Android学习笔记 通知Notification
- Android学习笔记(一)之Notification
- Android学习笔记,Notification通知事件
- Android学习笔记——Notification
- Android入门笔记 - 界面开发 - Notification, NotificationManager
- android开发之Notification学习笔记
- Android Notification的常规使用方法笔记
- Android学习笔记(32):通知推送Notification
- android笔记,点击notification时的跳到栈顶
- 笔记49 | Android通讯之Notification[转]
- ANdroid Notification
- android notification
- android notification
- Java对存储过程的调用方法
- 学习JMF框架遇到的问题及总结
- UVA - 10306 e-Coins
- solaris查看内存、CPU、硬盘总数和使用情况情况
- urllib 传参
- android笔记16-Notification
- c++之指针作为函数参数传递的问题
- Beginning Auto Layout Tutorial in iOS 7: Part 1
- Android的计量单位px,in,mm,pt,dp,dip,sp
- android笔记17- 各种menu
- maven核心,pom.xml详解
- JVM(java 虚拟机)内存设置
- 网络游戏和实现语言
- TCP/UDP 常用端口列表