So i have created this notification in my activity
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("New mail from " + sender)
.setContentText(subject)
.setSmallIcon(R.drawable.notification)
.build();
How can i now show it in status/notification bar along with the sound?
The user can reveal the Notifications window by pulling down the status bar (or selecting Notifications from the Home options menu).
To change how icons and notifications appearPress and hold or right-click any empty space on the taskbar and select Taskbar settings. Under Taskbar corner icons: Select On for any icons you want to see on the taskbar. Select Off for any icons you don't want to see on the taskbar.
There is some good documentation at android developer site and have a look at the NotificationManager doc's
Here you go, some code...:
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, n);
Note that it is also a goo idea to add your intend to the notification...
mBuilder.setContentIntent(resultPendingIntent);
To add sound you can use the Notification.Builder.setSound()
method.
How can i now show it in status/notification bar along with the sound?
Use the Notification.Builder.setSound()
method.
You can get the default ringtone like this:
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
and then set it as notification sound:
Notification.Builder(getApplicationContext()).setSound(uri);
and then after you've built your notification you launch it with:
myNotificationManager.notify(myNotificationId, n);
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