像Gmail应用程序的Andr​​oid多行通知 [英] Android multiple line notification like Gmail app

查看:150
本文介绍了像Gmail应用程序的Andr​​oid多行通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建像Gmail应用程序多行不通知如下图所示(5通知下一个通知分组)

I am trying to create a multiple line notification like the Gmail application does as shown in the image below (the 5 notifications grouped under one notification)

我尝试了各种例子,但只能似乎创建像

I have tried various examples but can only seem to create single notifications like

   public void createSingleNotification(String title, String messageText, String tickerttext) {
        int icon = R.drawable.notification_icon; // icon from resources
        CharSequence tickerText = tickerttext; // ticker-text
        long when = System.currentTimeMillis(); // notification time
        Context context = getApplicationContext(); // application Context
        CharSequence contentTitle = title; // expanded message title
        CharSequence contentText = messageText; // expanded message text
        Intent notificationIntent = new Intent(this, MainActivity.class);

        Bundle xtra = new Bundle();
        xtra.putString("title", title);
        xtra.putString("message", messageText);

        notificationIntent.putExtras(xtra);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
          notificationIntent, PendingIntent.FLAG_ONE_SHOT
            + PendingIntent.FLAG_UPDATE_CURRENT);
        String ns = Context.NOTIFICATION_SERVICE;

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        Notification notification = new Notification(icon, tickerText, when);
        notification.setLatestEventInfo(context, contentTitle, contentText,   contentIntent);
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.FLAG_AUTO_CANCEL;
        notification.flags = Notification.DEFAULT_LIGHTS
          | Notification.FLAG_AUTO_CANCEL;
        final int HELLO_ID = 0;
        mNotificationManager.notify(HELLO_ID, notification);
      }

我不知道如何创建一个我可以添加行的通知组。

I am not sure how to create a notification group that I can add lines to.

推荐答案

您正在寻找的大景观记录在Android官方文档:<一href="https://developer.android.com/guide/topics/ui/notifiers/notifications.html">https://developer.android.com/guide/topics/ui/notifiers/notifications.html

You are looking for "Big View" documented in official Android docs: https://developer.android.com/guide/topics/ui/notifiers/notifications.html

这篇关于像Gmail应用程序的Andr​​oid多行通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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