推送:在通知区域显示所有通知

Push: show all notifications in the notifications area

在我的应用程序中,我插入了推送通知管理。现在我只测试 Android 区域。

我使用 FCM 控制台发送了第一个测试通知。使用此工具,如果我发送多个通知,我会在 phone 的通知区域看到所有通知(例如:如果我发送 3 条通知,文本为“1”、“2”和“3” , 我都在通知区看到了)。

然后,我尝试编写一些 C# 代码来从我的服务器发送这些通知。我现在可以从我的代码发送通知,但如果我进行与上面相同的测试,我只会看到最后一个通知(“3”),而不是所有通知。

我确定要设置一些参数,但我不知道是哪个。

你知道我要在哪里修理东西吗?在我的 C# 代码下面:

public string SendMessage()
{
    string serverKey = "myserverkey";

    try
    {
        var result = "-1";
        var webAddr = "https://fcm.googleapis.com/fcm/send";

        var regID  = "myAndroidPhoneID";


        var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Headers.Add("Authorization:key=" + serverKey);
        httpWebRequest.Method = "POST";

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{\"to\": \"" + regID + "\",\"data\": {\"message\": \"1This is a Firebase Cloud Messaging Topic Message!\",},\"priority\":10}";
            streamWriter.Write(json);
            streamWriter.Flush();
        }

        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            result = streamReader.ReadToEnd();
        }

        return result;
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
        return "err";
    }
}

我也尝试在我的 json 中添加参数 collapse_key,每次通知都会更改它的值,但我总是只看到最后一个。

使用这个 json 而不是发布的解决:

string json = "{\"to\": \"" + regID + "\",\"notification\": {\"title\": \"New deal\",\"body\": \"20% deal!\"},\"priority\":10}";

这里总结了所有步骤:https://programmingistheway.wordpress.com/2017/07/19/devextremephonegap-how-to-manage-push-notifications-with-fcm/