簡體   English   中英

使用Android Firebase堆疊推送通知

[英]Stack push notifications with Android Firebase

我開發了Android應用程序,使用Firebase接收推送通知。 我的代碼基於Firebase / Google官方文檔( https://firebase.google.com/docs/cloud-messaging/android/clienthttps://firebase.google.com/docs/cloud-messaging/android/receive並沒有什么特別之處,它有擴展FirebaseMessagingService的服務和擴展FirebaseInstanceIdService的服務。 一切正常。

但是這個應用程序收到的通知超出預期,我的客戶希望應用程序堆疊收到的通知。 我已經看過教程解決方案在舊的GCM機制上工作但FCM沒有。 所以我的懷疑是:是否可以使用FCM堆疊收到的推送通知? 或者在后端以某種方式編碼?

堆疊通知可以使用FCM完成,它也需要在服務器端進行一些更改。 所有這些都在這里詳細解釋: -

https://stackoverflow.com/a/43913156/6157185

 NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID);
    Notification mNotification = builder
            .setLargeIcon(image)/*Notification icon image*/
            .setContentText(messageBody)
            .setSmallIcon(R.drawable.dhlone)
            .setContentTitle("DHL")
            .setStyle(new NotificationCompat.BigPictureStyle()
                    .bigPicture(image).bigLargeIcon(image))/*Notification with Image*/
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)
           .setBadgeIconType(R.drawable.dhlone)
            .setAutoCancel(true)

//使用set setAutoCancel(true)。 它會工作

您只需將.setGroup(GROUP_KEY_XPTO)添加到通知構建器即可。 具有相同組ID的所有通知將被堆疊。

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

在下一個通知中:

Notification notif2 = new NotificationCompat.Builder(mContext)
         .setContentTitle("New mail from " + sender2)
         .setContentText(subject2)
         .setSmallIcon(R.drawable.new_mail)
         .setGroup(GROUP_KEY_EMAILS)
         .build();

notificationManager.notify(notificationId2, notif2);

在此處查看更多相關信息: https//developer.android.com/training/wearables/notifications/stacks.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM