Group notifications on Android

痴心易碎 提交于 2019-12-07 12:43:25
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());

To create a stack, call setGroup() for each notification you want in the stack and specify a group key.

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);

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!