[英]Notification like whatsapp or sms app android
我想創建一個通知視圖,就像 whatsapp 或短信通知一樣。我怎樣才能做到這一點。
到目前為止我所搜索的
面包丁:可以在這里找到
這將在運行活動和下方的操作欄上顯示一個面包丁。 如果我的活動沒有運行或者我正在進行其他活動,這如何處理。
吐司:這看起來不像吐司。 它只顯示在底部或中心。
Dialog :這可以像這樣完成,但這會使應用程序變得模糊。 並禁用背景。 我不想要這個
任何解決方案將不勝感激。
謝謝
這是一個來自 android 棒棒糖的單挑通知在這里你檢查如何顯示你可以在這里看到的通知http://developer.android.com/guide/topics/ui/notifiers/notifications.html並且對於單挑你必須將通知優先級設置為以下
.setPriority(Notification.PRIORITY_HIGH)
希望能幫助到你
編輯 11 月 17 日
Notification.PRIORITY_HIGH在 API 級別 26 中已棄用。請改用(NotificationManager.IMPORTANCE_HIGH) 。
它可以通過 Headsup 通知來完成。 這是 Andorid L 的特性,所以這里的代碼是演示
Notification createNotification(boolean makeHeadsUpNotification) {
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setPriority(Notification.PRIORITY_DEFAULT)
.setContentTitle("Sample Notification")
.setContentText("This is a normal notification.");
if(Build.VERSION.SDK_INT> Build.VERSION_CODES.KITKAT)
{
notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE);
}
if (makeHeadsUpNotification) {
Intent push = new Intent();
push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
push.setClass(this, IndexActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
push, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder
.setContentText("Heads-Up Notification on Android L or above.")
.setFullScreenIntent(fullScreenPendingIntent, true);
}
return notificationBuilder.build();
}
你可以這樣稱呼它
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context
.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, createNotification(
true));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.