The documentation says Notification.Builder is Added in API level 11. Why I get this lint error?
Call requires API level 16 (current min is 14): android.app.Notification.Builder#build
notification = new Notification.Builder(ctx)
.setContentTitle("Title").setContentText("Text")
.setSmallIcon(R.drawable.ic_launcher).build();
Manifest:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
Am I missing something?
Correct me if I am wrong but the API is added in level 11, right? Added in API level 11
NotificationBuilder.build() requires API Level 16 or higher. Anything between API Level 11 & 15 you should use NotificationBuilder.getNotification(). So use
notification = new Notification.Builder(ctx)
.setContentTitle("Title").setContentText("Text")
.setSmallIcon(R.drawable.ic_launcher).getNotification();
The tip about the API level needing to be 16 is right. This worked for me
if (Build.VERSION.SDK_INT < 16) {
nm.notify(MY_NOTIFICATION_ID, notificationBuilder.getNotification());
} else {
nm.notify(MY_NOTIFICATION_ID, notificationBuilder.build());
}
I was having the problem where the notification worked fine on newer devices but not on Android 4.0.4 (API level 15). I do get a deprecation warning form eclipse. @SuppressWarnings("deprecation") doesn't entirely hide it but I think that is probably helpful.
Android Lint is a new tool introduced in ADT 16 (and Tools 16) which scans Android project sources for potential bugs. It is available both as a command line tool, as well as integrated with Eclipse
http://tools.android.com/tips/lint
For list of lint checks
http://tools.android.com/tips/lint-checks
For supressing lint warning
http://tools.android.com/tips/lint/suppressing-lint-warnings
http://developer.android.com/reference/android/app/Notification.Builder.html
If your app supports versions of Android as old as API level 4, you can instead use NotificationCompat.Builder, available in the Android Support library.
For support library
http://developer.android.com/tools/extras/support-library.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With