Why does it say "deprecated" for a method when its the only one I can use for the selected API-level?

android, sdk

Solution

So why am I getting the deprecated warning even though its the only one I can and should use?

Because your build target is API Level 16 or higher, where this method is deprecated.

One might think that the warning/docs should adapt to the minSdkLevel, not the highets one

In that case, one would be incorrect. Deprecation has nothing to do with `minSdkVersion`, any more than it would in standard Java outside of Android (where deprecation exists and `minSdkVersion` does not).

Moreover, you should be using the Android Support package's version of `Notification.Builder` (called `NotificationCompat.Builder`, since the native one does not exist in API Level 10, which your manifest indicates that you are trying to support. `build()` should exist on `NotificationCompat.Builder` and work on all your desired API levels.

Problem

In my Android manifest, it says this: ``` <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" /> ``` but when I write this code, the getNotification at the end gets me warning saying that the method is "deprecated": ``` Notification myNotification = new Notification.Builder(appContext) .setContentTitle("SIC") .setContentText(tickerText) .setWhen(when) .setDefaults(Notification.DEFAULT_SOUND) .setAutoCancel(true) .setContentIntent(contentIntent) .getNotification(); // <-- warning here ``` Now, the problem is that for API-level 10, which is the minimum I am developing for, getNotification is the only one there is to use. The newer method called "build()" is for API-level 16. So why am I getting the deprecated warning even though its the only one I can and should use? One might think that the warning/docs should adapt to the minSdkLevel, not the highets one...

Original source