Reputation: 7846
According to the documentation that I've seen, the android notification builder was introduced in API 11, and:
Upvotes: 5
Views: 4023
Reputation: 1007296
If your app supports devices older than API Level 11, you should be using NotificationCompat.Builder
, in which case you can just use build()
all of the time.
Otherwise, you are welcome to just call getNotification()
, until such time as you are willing to support only API Level 16 and higher. They simply renamed the method for greater consistency. If you look at the source code, getNotification()
just calls build()
on newer devices.
There's nothing wrong with using Raghav's approach, and that sort of technique will be required in other situations where there are API level differences.
Upvotes: 15
Reputation: 82563
You can check the API level at Runtime.
if (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.JELLY_BEAN) {
// call something for API Level 16+
} else if (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.HONEYCOMB) {
// call something for API Level 11+
}
Upvotes: 5