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