没有“抬头"的通知; [英] Notification without "heads up"

查看:271
本文介绍了没有“抬头"的通知;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个具有较高优先级的通知(正在聊天的应用程序),但是我的客户要求该通知没有抬头"视图.

I am trying to create a notification that has a high priority (a chatting app) but my client requested that there will be no "heads up" view for it.

我尝试为RemoteViews创建一个空布局以将其设置为Notification.headsUpContentView,但还是一无所获.

I have tried creating an empty layout for a RemoteViews to set as the Notification.headsUpContentView but still nothing.

这是我尝试过的:

    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" />

推荐答案

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

If you insist on using PRIORITY_MAX, you can disable the Heads-Up notification using the following code starting with API 21:

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

这篇关于没有“抬头"的通知;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆