Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call requires API level 16 (current min is 14): android.app.Notification.Builder#build

enter image description hereThe 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

like image 833
pt2121 Avatar asked May 08 '13 16:05

pt2121


3 Answers

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();
like image 133
stinepike Avatar answered Nov 09 '22 10:11

stinepike


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.

like image 39
formica Avatar answered Nov 09 '22 10:11

formica


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

like image 5
Raghunandan Avatar answered Nov 09 '22 11:11

Raghunandan