I need to create a simple notification which will be shown in notification bar along with the sound and icon if possible? I also need it to be compatitible with Android 2.2, so i found that NotificationCompat.Builder works with all APIs above 4. If there’s a better solution, feel free to mention it.
Share
The NotificationCompat.Builder is the most easy way to create
Notificationson all Android versions. You can even use features that are available with Android 4.1. If your app runs on devices with Android >=4.1 the new features will be used, if run on Android <4.1 the notification will be an simple old notification.To create a simple Notification just do (see Android API Guide on Notifications):
You have to set at least
smallIcon,contentTitleandcontentText. If you miss one the Notification will not show.Beware: On Gingerbread and below you have to set the content intent, otherwise a
IllegalArgumentExceptionwill be thrown.To create an intent that does nothing, use:
You can add sound through the builder, i.e. a sound from the RingtoneManager:
The Notification is added to the bar through the NotificationManager: