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.
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.Textplaced in the request’s body and it needs to be URL Encoded, since that I just encoded theTextBox1.Textvalue which solve my problem and let my android app received notification in arabic languge:I only changed my asp.net code from this:
To be Like the following:
and keep my android code as its.