在聊天应用程序中使用什么通知系统?

在聊天应用程序中使用什么通知系统?

问题描述:

我正在 Android 中使用 Firebase 数据库开发聊天应用程序.

I'm developing a chat application using Firebase Database in Android.

我已经完成了核心(聊天和用户列表活动),但我还没有完成通知系统.

I've already done the core (chat and user's list activities), but I have yet to do the notification system.

我想在使用 firebase 时实现 Google FCM,但我发现其中有一个漏洞,因为我似乎无法处理传递给不在前台的 iOs 应用程序的所有通知.

I wanted to implement Google FCM as I am using firebase, but I find an hole in it, as it seems that I can not handle at all notifications delivered to iOs apps that are not in foreground.

数据通知文档

在 iOS 上,FCM 会存储消息并仅在应用处于前台并已建立 FCM 连接时传递消息.在 Android 上,客户端应用程序在 onMessageReceived() 中接收数据消息,并可以相应地处理键值对.

On iOS, FCM stores the message and delivers it only when the app is in the foreground and has established a FCM connection. On Android, a client app receives a data message in onMessageReceived() and can handle the key-value pairs accordingly.

即使应用程序在后台,我也需要捕捉数据通知,我特别需要它,因为我想更新应用程序图标上的徽章计数器,让用户知道他有多少未读消息.

And I need to catch the data notification even when the app is in background, I need that specifically because I want to update my badge counter on the app icon to let the user know how many unread messages he has.

我现在正在尝试 OneSignal 解决方案即使在后台也能收到通知,它是免费的并且与 GCM 接口.我很伤心不留在谷歌,但如果我不能更新使用FCM我必须寻找到另一侧的徽章计数.

I'm now tryng the OneSignal solution can receive notification even when in background, it's free and interfaces with GCM. I'm sad to not stay with Google but if I can't update the badge count using FCM I have to look to an other side.

任何考虑将不胜感激.

当应用处于后台或由于 FirebaseMessagingService 正在运行而未运行时,使用以下代码从服务器获取徽章.

Use below code for get badge from server when app is in background or not running because your FirebaseMessagingService is running.

如果您对在应用程序图标上显示徽章有任何疑问,请不要发表评论,因为就在昨天,我确实在应用程序图标上显示了徽章.

If you have any doubts regarding show badge on app icon than comment it because just yesterday i did show badge on app icon.

public class Custom_FirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "FirebaseMsgService";
    //private Activity strPushClickDesti;
    String activityName;

    @Override
    public void zzm(Intent intent) {
        Log.i("uniqbadge", "zzm");
        Set<String> keys = intent.getExtras().keySet();
        for (String key : keys) {
            try {
                 Log.i("uniq", " " + key + " " + intent.getExtras().get(key));
                if (key.equals("badge")) {
                    String cnt = intent.getExtras().get(key).toString();
                    int badgeCount = Integer.valueOf(cnt);
                    Log.i("uniq", " badge count " + badgeCount);
                    ShortcutBadger.applyCount(this, badgeCount);
                    Log.i("uniq", " " + "end");
                }
            } catch (Exception e) {
                Log.i("uniqbadge", "zzm Custom_FirebaseMessagingService" + e.getMessage());
            }
        }

        super.zzm(intent);
    }