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...
Deprecation means that we've ended official support for the APIs, but they will continue to remain available to developers. This page highlights some of the deprecations in this release of Android. To see other deprecations, refer to the API diff report.
Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future.
The @Deprecated annotation tells the compiler that a method, class, or field is deprecated and that it should generate a warning if someone tries to use it. That's what a deprecated class or method is. It's no longer relevant.
Using the @Deprecated Annotation To use it, you simply precede the class, method, or member declaration with "@Deprecated." Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element.
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.
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