Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Notification in Arabic Language using GCM

I am using GCM to send notification to android devices.

The code that I am using to get the message in GCMIntentService is as below:

@Override
    protected void onMessage(Context ctx, Intent intent) {
        // TODO Auto-generated method stub
        String j =intent.getStringExtra("message");
        generateNotification(ctx, j);
    }

And the code that I am using in server side to push or send those notification is as below:

Dim request As WebRequest = WebRequest.Create("https://android.googleapis.com/gcm/send")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.Headers.Add("Authorization: key=AIzaSyA47-XMaePL1mmI0P1yQ9V4sntMVn9q-1o")
request.Headers.Add("Sender: id=648406549877")
Dim collapsKey = Guid.NewGuid.ToString("n")
Dim postdata As String = "registration_id=" + regid_String_reveived_from_device_after_registering_with_GCM + "&data.message=" + TextBox1.Text + "&collapse_key=" + collapsKey
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim resposne As WebResponse = request.GetResponse
Dim dataresponse As Stream = resposne.GetResponseStream
Dim reader As New StreamReader(dataresponse)
Dim sResponseFromServer As String = reader.ReadToEnd
Label2.Text = sResponseFromServer
reader.Close()
dataresponse.Close()
resposne.Close

When I sent any notification in English Language using the above code I received it in my device with no problem at all, But When I sent notification in Arabic language using the above code I got nothing as message which appear to me as blank in both Logcat and notification. The android API that I am using to develop this app is 16.

So how can I get the message that written in Arabic as notification, the same way that I get those messages when sent by English.

Is the problem from ASP.Net Side or android Side.

Any help or redirection will be completely appreciated.

like image 759
Husam A. Al-ahmadi Avatar asked Dec 22 '12 17:12

Husam A. Al-ahmadi


People also ask

What is GCM notification?

Google Cloud Messaging (GCM) was a mobile notification service developed by Google that enables third-party application developers to send notification data or information from developer-run servers to applications that target the Google Android Operating System, as well as applications or extensions developed for the ...

Is FCM and GCM the same?

Firebase Cloud Messaging (FCM), formerly known as Google Cloud Messaging (GCM), is a cross-platform cloud solution for messages and notifications for Android, iOS, and web applications, which as of June 2022 can be used at no cost.

Can I send push notifications without FCM?

Gotify is self-hosted open source notification solution that you can use it to send push notification to your android app without need of Firebase. with help of UnifiedPush you can receive push notifications in your android app.

How do I send FCM push notifications?

For sending FCM notification payload you can use Firebase Cloud Messaging Tool in firebase console. And click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.


1 Answers

I solved the above problem which I was facing for one week by doing the following:

the message that I sent from the ASP.net side which is represented as TextBox1.Text placed in the request's body and it needs to be URL Encoded, since that I just encoded the TextBox1.Text value which solve my problem and let my android app received notification in arabic languge:

I only changed my asp.net code from this:

Dim postdata As String = "registration_id=" + regid(i) + "&data.message=" + TextBox1.Text + "&collapse_key=" + collapsKey

To be Like the following:

Dim postdata As String = "registration_id=" + regid(i) + "&data.message=" + HttpUtility.UrlEncode(TextBox1.Text) + "&collapse_key=" + collapsKey

and keep my android code as its.

like image 114
Husam A. Al-ahmadi Avatar answered Sep 29 '22 16:09

Husam A. Al-ahmadi