使用 firebase 在 android 中发送推送通知

send push notifications in android using firebase

我有三个应用程序。使用 Asp.NET MVC、Asp.NET Web API 应用程序和 Android 应用程序开发的内容管理系统。我使用 SQL Server 2016 作为我的数据库。内容管理系统和 Android 应用程序通过 Web API.

执行数据库操作

现在我需要在我的 Android 应用程序中实现推送通知。每当管理员 post 来自内容管理系统的新数据时,android 应用程序用户应该会在他们的 phone.

中收到推送通知

我该如何实施?我在网上浏览了各种教程。他们已经使用 Firebase 实现了。我明白这一点。但他们也使用了 php 脚本和 WAMP 服务器来实现。我不熟悉php。

谁能告诉我如何在不使用 php 的情况下在我的场景中实现推送通知?我将不胜感激。

谢谢

ASP 方使用 FCM

try
        {
            var applicationID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            var senderId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            string deviceId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
            tRequest.Method = "post";
            tRequest.ContentType = "application/json";
            var data = new
            {
                to = deviceId,
                notification = new
                {
                    body = "This is the message Body",
                    title = "This is the title of Message",
                    icon = "myicon"
                },
                priority = "high"

            };

            var serializer = new JavaScriptSerializer();
            var json = serializer.Serialize(data);
            Byte[] byteArray = Encoding.UTF8.GetBytes(json);
            tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
            tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
            tRequest.ContentLength = byteArray.Length;

            using (Stream dataStream = tRequest.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);

                using (WebResponse tResponse = tRequest.GetResponse())
                {
                    using (Stream dataStreamResponse = tResponse.GetResponseStream())
                    {
                        using (StreamReader tReader = new StreamReader(dataStreamResponse))
                        {
                            String sResponseFromServer = tReader.ReadToEnd();
                            Response.Write(sResponseFromServer);
                            Label3.Text = sResponseFromServer;
                        }
                    }
                }
            }
        }

        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }


    }

android 端使用 FCM 遵循 link

https://www.codementor.io/flame3/send-push-notifications-to-android-with-firebase-du10860kb