Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification builder getNotification() vs build()

According to the documentation that I've seen, the android notification builder was introduced in API 11, and:

  • In API 11 to API 15, one uses the method .getNotification() to create the notification object
  • In API 16 onwards, one uses the .build() to create the notificaiton object.
That sounds straightforward enough, but how do I write code in Eclipse that'll call the right method depending on the API version?
like image 538
Stochastically Avatar asked Apr 20 '13 17:04

Stochastically


1 Answers

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.

like image 105
CommonsWare Avatar answered Sep 30 '22 17:09

CommonsWare