【发布时间】:2016-07-09 20:26:54
【问题描述】:
我正在使用此代码创建一个提醒通知。
private static void showNotificationNew(final Context context,final String title,final String message,final Intent intent, final int notificationId, final boolean isHeaderNotification) {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context.getApplicationContext())
.setSmallIcon(R.drawable.prime_builder_icon)
.setPriority(Notification.PRIORITY_DEFAULT)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle(title)
.setContentText(message)
.setWhen(0)
.setTicker(context.getString(R.string.app_name));
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder.setContentText(message);
if(isHeaderNotification) {
notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, false);
}
notificationBuilder.setContentIntent(fullScreenPendingIntent);
notificationBuilder.setAutoCancel(true);
Notification notification = notificationBuilder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(notificationId, notification);
}
问题是,通知应该占据顶部屏幕的很大一部分以引起用户注意,但几秒钟后它应该消失并且应该出现正常通知。
但是这段代码并没有这样做。通知会一直占据整个顶部屏幕,直到用户将其关闭。
我正在考虑在几秒钟后使用 Handler 创建另一个具有相同 ID 的普通通知,但我想知道是否有更好的方法来做到这一点。
按照 WhatsApp 的示例,模拟我想要的行为。
【问题讨论】:
标签: android notifications heads-up-notifications