Android Notification.setLatestEventInfo弃用和Notification.Builder用法
来源:互联网 发布:苹果电脑双系统卸载mac 编辑:程序博客网 时间:2024/05/27 09:44
今天在学习小米便签的源码的时候,至于源码的地址,http://m.blog.csdn.net/article/details?id=50544248 ,里面有好多github的开源项目,打开项目,报错2处,一处就是便是找不到setLatestEventInfo()这个方法,我用的api6.0编译的,在这个api这个方法时被弃用的,采用Notification.Builder来代替,
原来的用法:1首先是拿到NotificationManager这个管理类实例,
mNotifiManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE);
2.创建Notification实例,第一个参数是传入通知的图片,第二个是传入通知的标题,这里采用的getString的方法,顺带一提,getString方法时通过参数tickerId来调用xml文件里的常量,一般这个值为R.String.xxx
Notification notification =new Notification(R.drawable.notification, mContext.getString(tickerId), System.currentTimeMillis())
3调用setLatestEvent(xx),里面有四个参数,分别是context,标题,内容,和pendingIntnet 4个参数
notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, pendingIntent);
4.d调用NotificationManager的notify(xx)方法,接收两个参数一个id,可用于取消通知的时候用,另一个是Notification的实例
新的:在APi6.0时方法2,和3步骤被弃用,用过Notification.Builder来创建,直接来看官方的提供代码例程吧`
Notification noti = new Notification.Builder(mContext) .setContentTitle("New mail from " + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.new_mail) .setLargeIcon(aBitmap) .build();
他是通过穿件一个Notification.Builder对象,并对这个对象进行设置,然后调用build方法来返回一个Notification对象,最后再执行上述第四个步骤,这里要注意的是,替代setLatestEventInfo(xxx)方法除了上述设置标题和内容,里面还有一个setContentIntent(pendingIntent)来设置点击通知后调用的Intent,还有其他方法详见Android官方文档http://developer.android.com/reference/android/app/Notification.Builder.html
- Android Notification.setLatestEventInfo弃用和Notification.Builder用法
- Android Notification.setLatestEventInfo弃用和Notification.Builder用法
- Android Notification.setLatestEventInfo弃用和Notification.Builder用法
- notification.builder代替notification的setLatestEventInfo()方法
- Android Notification.setLatestEventInfo(...)
- Android Notification.setLatestEventInfo()警告
- Notification中setLatestEventInfo(),Builder.getNotification()过时
- Android Notification的setLatestEventInfo()@deprecate
- notification新旧用法 notification builder
- notification新旧用法 notification builder
- Android-通知Notification、Notification.Builder和NotificationCompat.Builder兼容
- Android Studio 使用Notification.setLatestEventInfo红字错误
- android-Notification.Builder
- notification.setLatestEventInfo过时
- android SDK23 Notification通知setLatestEventInfo方法失效 和httpclient失效的解决方案
- Notification通知setLatestEventInfo方法失效
- [Android] Notification.setLatestEventInfo()方法被移除的问题
- Android中关于setLatestEventInfo()过时以及构建Notification的解决方法
- 使用ViewPagerIndicator结合ViewPager实现网易新闻客户端的Tab标签效果
- 多线程编程(二)——线程结束后的处理&主服务存活方法
- _free_base 崩溃
- jquery ajax
- camp day2
- Android Notification.setLatestEventInfo弃用和Notification.Builder用法
- leetcode303-Range Sum Query - Immutable
- poj 1797 Heavy Transportation(通路中的最大承载量)
- zookeeper配置开机启动失效分析
- VB把excel数据导入ACCESS
- 渣渣的大数相比 - 我果然机智
- 读《大话设计模式》——适配器模式
- POJ 1942(组合数学)
- AccessibilityService之微信抢红包辅助功能实现