【问题标题】:Group notifications on AndroidAndroid 上的群组通知
【发布时间】:2017-01-17 08:43:21
【问题描述】:

我想像图片一样显示通知。如果不止一个,我也想展示一个柜台。我没有在官方文档中找到信息。现在我只是通过 id 更新我的通知:

((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
                .notify(PUSH_NOTIFICATION_ID, notification);

我该怎么做?

【问题讨论】:

    标签: android push-notification android-notifications


    【解决方案1】:
    NotificationCompat.Builder mBuilder = new  NotificationCompat.Builder(getApplicationContext());
                mBuilder.setSmallIcon(R.mipmap.ic_launcher);
                mBuilder.setContentTitle(topic);
                mBuilder.setContentText(new String(message.getPayload()));
                mBuilder.setAutoCancel(true);
                mBuilder.mNumber = 1;//get your number of notification from where you have save notification
    
                NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                mNotifyMgr.notify(notify_id, mBuilder.build());
    

    【讨论】:

    • 谢谢,稍后再试)
    • 什么是mNumber
    【解决方案2】:

    要创建堆栈,请为堆栈中所需的每个通知调用 setGroup() 并指定组键。

    final static String GROUP_KEY_EMAILS = "group_key_emails";
    
        // Build the notification, setting the group appropriately
        Notification notif = new NotificationCompat.Builder(mContext)
                 .setContentTitle("New mail from " + sender1)
                 .setContentText(subject1)
                 .setSmallIcon(R.drawable.new_mail)
                 .setGroup(GROUP_KEY_EMAILS)
                 .build();
    
        // Issue the notification
        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(this);
        notificationManager.notify(notificationId1, notif);
    

    参考:https://developer.android.com/training/wearables/notifications/stacks.html

    【讨论】:

    • 谢谢,今天晚些时候会检查。)
    • @RuslanPodurets 有帮助吗?
    • 没有。 (通知就像我的代码一样更新(
    • @SaikCaskey,虽然知道这样的标志不存在是有价值的,但您可以通过概述如何构建更智能的通知显示类的示例来增加更多价值,一个解决OP的问题。
    猜你喜欢
    • 2014-04-22
    • 2014-11-18
    • 2017-03-24
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    相关资源
    最近更新 更多