【发布时间】:2016-06-29 21:01:28
【问题描述】:
我正在使用此代码发送本地通知
mNotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
i, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setContentTitle(title)
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify((int)value, mBuilder.build());
但是,如果手机屏幕被滑动锁定,它们会显示在状态栏上。我想在屏幕顶部显示推送通知,例如 whatsapp、facebook、短信等。
我怎样才能做到这一点?
【问题讨论】:
-
我认为 Android OS 会自动处理它
-
@HirenPatel 好吧,不,我只在状态栏上看到小图标,而不是在锁定屏幕顶部显示
-
默认情况下仅在 android 5 (lolipop) 支持抬头通知。因此,如果您仍然想这样做,那么您可以构建自定义通知视图并使用 windowmanager 服务将其添加到屏幕中。
标签: java android eclipse android-studio