
文档中说,Notification.Builder是在API 11中添加的。为什么我会得到这个lint错误?
调用需要API级别16 (当前最小值为14):android.app.Notification.Builder#build
notification = new Notification.Builder(ctx)
.setContentTitle("Title").setContentText("Text")
.setSmallIcon(R.drawable.ic_launcher).build();清单:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />我是不是遗漏了什么?
如果我错了,但是API是在11级中添加的,对吗?在API级别11中添加
发布于 2013-05-08 16:44:47
NotificationBuilder.build()要求API级别16或更高。在API 11和15之间的任何东西,都应该使用NotificationBuilder.getNotification()。所以用吧
notification = new Notification.Builder(ctx)
.setContentTitle("Title").setContentText("Text")
.setSmallIcon(R.drawable.ic_launcher).getNotification();发布于 2014-12-31 09:56:38
关于API级别需要为16的提示是正确的。这对我来说很管用
if (Build.VERSION.SDK_INT < 16) {
nm.notify(MY_NOTIFICATION_ID, notificationBuilder.getNotification());
} else {
nm.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
}我遇到了这样的问题:通知在较新的设备上正常工作,而在Android4.0.4 (API级别15)上却不起作用。我确实收到了来自eclipse的警告。@SuppressWarnings(“贬义”)并不能完全隐藏它,但我认为这可能是有帮助的。
发布于 2013-05-08 16:44:03
Android是ADT 16 (和Tools 16)中引入的一种新工具,它扫描Android项目的源代码以查找潜在的bug。它既可作为命令行工具使用,也可与Eclipse集成
http://tools.android.com/tips/lint
用于检查皮棉的清单
http://tools.android.com/tips/lint-checks
用于压制棉布警告
http://tools.android.com/tips/lint/suppressing-lint-warnings
http://developer.android.com/reference/android/app/Notification.Builder.html
如果您的应用程序支持像API第4级那样的Android版本,则可以使用Android支持库中提供的NotificationCompat.Builder .。
用于支持库
http://developer.android.com/tools/extras/support-library.html
https://stackoverflow.com/questions/16445805
复制相似问题