没有 "heads up" 的通知
Notification without "heads up"
我正在尝试创建一个具有高优先级的通知(聊天应用程序),但我的客户要求不会有 "heads up" 视图。
我已经尝试为 RemoteViews
创建一个空布局以设置为 Notification.headsUpContentView
但仍然没有。
这是我试过的方法:
Intent target = new Intent(this, PushConsumedBroadcastReceiver.class);
target.putExtra(PushConsumedBroadcastReceiver.PUSH_TYPE, PushConsumedBroadcastReceiver.PUSH_TYPE_REMINDER);
PendingIntent pending = PendingIntent.getBroadcast(this, Constants.REQUEST_CODE_BASE, target, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this).setContentIntent(pending)
.setContentTitle(item.getNotificationText())
.setStyle(new BigTextStyle().bigText(item.getNotificationText()).setSummaryText("thepoosh looks good"))
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.g_icon_white)
.setPriority(Notification.PRIORITY_MAX)
.setTicker(item.getNotificationText())
.build();
if(VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
notification.headsUpContentView = new RemoteViews(getPackageName(), R.layout.empty_heads_up);
}
notification.sound = null;
notification.ledARGB = 0;
notification.vibrate = new long[0];
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(CODE_ONE_DAY_REMINDER, notification);
empty_heads_up.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
显示提醒通知是 the definition of a high-priority notification 的一部分:
If a notification's priority is flagged as High, Max, or full-screen, it gets a heads-up notification.
如果您不想要提醒通知,那么您就不需要高优先级通知。
请注意,您的用户可以选择禁用提醒通知或自行降低通知的优先级,但这是仅供用户使用的选项。
如果您坚持使用PRIORITY_MAX
,您可以使用以下以API 21:
开头的代码禁用Heads-Up通知
notification.headsUpContentView = new RemoteViews(Parcel.obtain());
我正在尝试创建一个具有高优先级的通知(聊天应用程序),但我的客户要求不会有 "heads up" 视图。
我已经尝试为 RemoteViews
创建一个空布局以设置为 Notification.headsUpContentView
但仍然没有。
这是我试过的方法:
Intent target = new Intent(this, PushConsumedBroadcastReceiver.class);
target.putExtra(PushConsumedBroadcastReceiver.PUSH_TYPE, PushConsumedBroadcastReceiver.PUSH_TYPE_REMINDER);
PendingIntent pending = PendingIntent.getBroadcast(this, Constants.REQUEST_CODE_BASE, target, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this).setContentIntent(pending)
.setContentTitle(item.getNotificationText())
.setStyle(new BigTextStyle().bigText(item.getNotificationText()).setSummaryText("thepoosh looks good"))
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.g_icon_white)
.setPriority(Notification.PRIORITY_MAX)
.setTicker(item.getNotificationText())
.build();
if(VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
notification.headsUpContentView = new RemoteViews(getPackageName(), R.layout.empty_heads_up);
}
notification.sound = null;
notification.ledARGB = 0;
notification.vibrate = new long[0];
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(CODE_ONE_DAY_REMINDER, notification);
empty_heads_up.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
显示提醒通知是 the definition of a high-priority notification 的一部分:
If a notification's priority is flagged as High, Max, or full-screen, it gets a heads-up notification.
如果您不想要提醒通知,那么您就不需要高优先级通知。
请注意,您的用户可以选择禁用提醒通知或自行降低通知的优先级,但这是仅供用户使用的选项。
如果您坚持使用PRIORITY_MAX
,您可以使用以下以API 21:
notification.headsUpContentView = new RemoteViews(Parcel.obtain());