java: 找不到符号 符号: 方法 setLatestEventInfoentInfo
2016-06-28 14:31
1136 查看
Error:(38,25)错误:找不到符号
符号:方法setLatestEventInfo(MyService,String,String,PendingIntent)
位置:类型为Notification的变量notification
解决:
如果编译的SDK版本在API23以上,就会出现这个问题,因为setLatestEventInfo方法在api23中被删掉了
在api4以上的版本用notification可以用supportv4中的NotificationCompat.Builder。android文档中给了一个例子:
Notificationnoti=newNotification.Builder(mContext)
.setContentTitle("Newmailfrom"+sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.build();
把上面"Notification.Builder"替换成"NotificationCompat.Builder"
alter+enter把supportv4中的相关的库import进来
importandroid.support.v4.app.NotificationCompat;
于是代码编程了这样
Notificationnotification;
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN){
notification=newNotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)//必须要先setSmallIcon,否则会显示默认的通知,不显示自定义通知
.setTicker("显示于屏幕顶端状态栏的文本")
.setContentTitle("thisicscontenttitle")
.setContentText("thisiscontenttext")
.setContentIntent(pendingIntent)
.build();
}else{
notification=newNotification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)//必须要先setSmallIcon,否则会显示默认的通知,不显示自定义通知
.setTicker("显示于屏幕顶端状态栏的文本")
.setContentTitle("thisiscontenttitle")
.setContentText("thisiscontenttext")
.setContentIntent(pendingIntent)
.build();
}
startForeground(2,notification);
注意:!!!上面这段代码是前台服务的notification,通过startForeground让服务变成前台服务并显示通知。这时必须要setSmallIcon,否则会显示默认的通知,不显示自定义通知!!!如果是正常的用NotificationManager显示通知则无所谓顺序
符号:方法setLatestEventInfo(MyService,String,String,PendingIntent)
位置:类型为Notification的变量notification
解决:
如果编译的SDK版本在API23以上,就会出现这个问题,因为setLatestEventInfo方法在api23中被删掉了
在api4以上的版本用notification可以用supportv4中的NotificationCompat.Builder。android文档中给了一个例子:
于是代码编程了这样
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN){
notification=newNotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)//必须要先setSmallIcon,否则会显示默认的通知,不显示自定义通知
.setTicker("显示于屏幕顶端状态栏的文本")
.setContentTitle("thisicscontenttitle")
.setContentText("thisiscontenttext")
.setContentIntent(pendingIntent)
.build();
}else{
notification=newNotification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)//必须要先setSmallIcon,否则会显示默认的通知,不显示自定义通知
.setTicker("显示于屏幕顶端状态栏的文本")
.setContentTitle("thisiscontenttitle")
.setContentText("thisiscontenttext")
.setContentIntent(pendingIntent)
.build();
}
startForeground(2,notification);
相关文章推荐
- Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
- Java编程学习1
- spring boot 学习笔记(003) 静态资源(html/js等文件)
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined解决方案
- Java接口
- 【Java基础】并发
- 【Java基础】通用程序设计
- 【Java基础】枚举和注解
- java之资源文件(.properties)读取
- 【Java基础】方法
- 【报错】ClassNotFoundException: javassist.util.proxy.MethodFilter
- 【报错】 ClassNotFoundException: javax.transaction.Synchronization
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合
- 本地eclipse运行hadoop程序,操作远程服务器(供理解和入门)
- Java每一天2
- Java RMI原理与使用
- jdk 多版本安装 for mac
- Eclipse Class Decompiler——Java反编译插件
- java安全框架-Shiro学习笔记(八)-加密工具类
- Java---Condition控制线程通信