[英]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.