[英]How to show notification in status bar?
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? 我现在如何在状态/通知栏中显示声音?
There is some good documentation at android developer site and have a look at the NotificationManager doc's 在android开发者网站上有一些很好的文档,看看NotificationManager文档
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. 要添加声音,可以使用Notification.Builder.setSound()
方法。
How can i now show it in status/notification bar along with the sound? 我现在如何在状态/通知栏中显示声音?
Use the Notification.Builder.setSound()
method. 使用Notification.Builder.setSound()
方法。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.