Help Me, I need Tutorial and Example Project Send Notification To Android Using Visual Basic 2008
Function SendAndroidSimpleFCMMEssage(ByVal Topic As String, ByVal Title As String, ByVal Body As String, ByVal ID As Integer) As Boolean
Dim HTTPClient As New HttpClient
Dim sKey As String = String.Empty
sKey = "YOUR_KEY"
Const QUOTE = """"
Dim js As New JavaScriptSerializer()
Dim Data As String = ""
Dim sID As String = String.Empty
sID = ID
Data = "{'priority':'high', 'to':'\/topics\/$TOPIC$','data':{'title':'$TITLE$','body':'$BODY$','id':'$ID$'}}".Replace("$TOPIC$", Topic).Replace("$TITLE$", (Title.Replace("'", String.Empty).Replace(QUOTE, String.Empty))).Replace("$BODY$", (Body.Replace("'", String.Empty).Replace(QUOTE, String.Empty))).Replace("$ID$", sID)
Data = Data.Replace("'", QUOTE)
Dim Request As New HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send")
Request.Content = New StringContent(Data, System.Text.Encoding.UTF8, "application/json")
HTTPClient.BaseAddress = New Uri("https://fcm.googleapis.com/fcm/send")
HTTPClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("key", "=" & sKey)
Dim result = HTTPClient.SendAsync(Request).Result
Dim oResult = result.Content.ReadAsStringAsync
If oResult.Result.Contains("message_id") Then
Return True
Else
Return False
End If
End Function
Private Sub BtnNotify_Click(sender As Object, e As EventArgs) Handles BtnNotify.Click
Dim n As New Firebase.PushNotification
n.SendNotification("/topics/and_topic-foobar", "Foo", "Bar")
End Sub
Don’t use this class because this is sending notifications to device id. It is simpler to use topic.Where i type this code
On class or on windows form
Imports System.Net
Imports Newtonsoft.Json
Public Class Notification
Public Sub SendNotification(ByVal deviceIDList As List(Of String), ByVal title As String, ByVal bodyMsg As String)
Dim fcmPath As String = "https://fcm.googleapis.com/fcm/send"
Dim serverKey As String = "AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoCAeI"
Dim senderID As String = "35xxxxxxx37"
Dim request As HttpWebRequest = CType(HttpWebRequest.Create(fcmPath), HttpWebRequest)
With request
.Method = "POST"
.ContentType = "application/json"
.Headers.Add(String.Format("Authorization: key={0}", serverKey))
.Headers.Add(String.Format("Sender: id={0}", senderID))
End With
Using streamWriter = New StreamWriter(request.GetRequestStream())
Dim webObject As New WebRequestFcmData
With webObject
.registration_ids = deviceIDList
.notification.title = title
.notification.body = bodyMsg
.notification.content_available = True
.notification.sound = "default"
.notification.priority = "high"
End With
Dim body = JsonConvert.SerializeObject(webObject)
With streamWriter
.Write(body)
.Flush()
.Close()
End With
End Using
Dim httpResponse = CType(request.GetResponse(), HttpWebResponse)
Using streamReader As New StreamReader(httpResponse.GetResponseStream)
Dim result = streamReader.ReadToEnd
End Using
End Sub
End Class
Public Class WebRequestFcmData
Public Property registration_ids As List(Of String)
Public Property notification As New NotificationData
End Class
Public Class NotificationData
Public Property body As String
Public Property content_available As Boolean
Public Property priority As String
Public Property title As String
Public Property sound As String
End Class