繁体   English   中英

如何在状态栏中显示通知?

[英]How to show notification in status bar?

所以我在我的活动中创建了这个通知

Notification n = new Notification.Builder(getApplicationContext())
    .setContentTitle("New mail from " + sender)
    .setContentText(subject)
    .setSmallIcon(R.drawable.notification)
    .build();

我现在如何在状态/通知栏中显示声音?

在android开发者网站上有一些很好的文档,看看NotificationManager文档

你去,一些代码......:

NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, n);

请注意,将通缉添加到通知中也是一个好主意...

mBuilder.setContentIntent(resultPendingIntent);

要添加声音,可以使用Notification.Builder.setSound()方法。

我现在如何在状态/通知栏中显示声音?

使用Notification.Builder.setSound()方法。

你可以得到这样的默认铃声:

Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

然后将其设置为通知声音:

Notification.Builder(getApplicationContext()).setSound(uri);

然后在您构建通知后,使用以下命令启动它:

myNotificationManager.notify(myNotificationId, n);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM