没有"通知的通知"

时间:2015-08-10 15:20:48

标签: android android-notifications heads-up-notifications

我正在尝试创建一个具有高优先级的通知(一个聊天应用)但我的客户要求没有"抬头"查看它。

我尝试为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" />

2 个答案:

答案 0 :(得分:1)

显示抬头通知是the definition of a high-priority notification

的一部分
  

如果通知的优先级被标记为高,最高或全屏,则会收到抬头通知。

如果您不想要提前通知,则不需要高优先级通知。

请注意,您可以选择禁用抬头通知或降低通知本身的优先级,但这仅供用户选择。

答案 1 :(得分:0)

如果您坚持使用PRIORITY_MAX,则可以使用以API 21开头的以下代码禁用Heads-Up通知:

notification.headsUpContentView = new RemoteViews(Parcel.obtain());