![](/img/trans.png)
[英]Android how to hide NotificationCompat.Builder notification`s icon on status bar?
[英]Android Status bar notification with NotificationCompat.Builder. Correct way to implement?
我一直在閱讀有關如何正確執行狀態欄通知的信息,但是大多數解決方案都使用不推薦使用的功能。 我認為NotificationCompat.Builder是解決我的問題的最佳方法。 有人可以給我示例代碼嗎?
對於像我這樣的新手來說,我發現的最好例子似乎並不明確。 我不知道是否必須在函數中實現代碼並調用它,還是必須將代碼粘貼到活動區域中。
使用NotificationCompat.Builder進行通知
預先感謝您的幫助和時間。
最后是創建簡單通知的方法:
public void createNotification() {
// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("Advice")
.setContentText("blahblahblahblah.").setSmallIcon(R.drawable.icon).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}
它會引發“呼叫需要API級別11”錯誤,但是通過右鍵單擊項目-> Android工具-> Clean Lint Markers可以解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.