How to show notification in status bar?

∥☆過路亽.° 提交于 2019-12-05 06:01:22

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!