Bluemix push notification for android is not sending any notifications - android

I'm trying to use the sample code available here: https://github.com/ibm-bluemix-mobile-services/bms-samples-android-hellopush
And the first difficulty I found was on configuring the GCM - it seems that somethings changed since it was documented - anyway I guess I got everything configured correctly.
I got the app working and I'm able to register my device, but there is no notification when I try to send it. I'm using both the bluemix dashboard and the swagger to send a message. The response I get is that the message was sent, but I got nothing on the device (a mobile phone, not the emulator).
I checked my Google API dashboard, and there is no activity on the GCM api.
The application ID is: f97eb706-3375-438d-8221-cd7ac0266de1

I was using Postman to test the GCM API (https://android.googleapis.com/gcm/send) and I was getting an "Error 401 Unauthorized". I tried to create a new API Key, but without success.
After reading this: https://stackoverflow.com/a/22453025/6828416
I tried to create a new project on GCM, and it suddenly started to work.

The Docs are currently being updated for GCM, so that will be fixed very soon.
I attempted to recreate your problem and just tested out the sample with Push Notifications with the Android sample here (with the latest version of Android Studio v2.1.3):
Before:
After:
Here is how I edited my code snippets after cloning the sample (mock values):
Code Edit 1 Before:
BMSClient.getInstance().initialize(this, "<APPLICATION_ROUTE>", "<APPLICATION_ID>", BMSClient.REGION_US_SOUTH);
Code Edit 1 After:
BMSClient.getInstance().initialize(this, "http://imfpush.ng.bluemix.net", "dfadsfadsfdsf-2343-2334-8e82-421c02ce847c", BMSClient.REGION_US_SOUTH);
Code Edit 2 Before:
push.initialize(this, "<APPLICATION_ID>", "<CLIENT_SECRET>");
Code Edit 2 After:
push.initialize(this, "dfadsfadsfdsf-2343-2334-8e82-421c02ce847c", "edec64df-34fd-44e3-9d1e-dfsfsdf989899");
I got these values from the Push Notifications service credentials (mock values).
Here is how I set up GCM:
In my Bluemix config, it looks something like this (mock values):
Here's how I got those values from GCM (mock values):
Sender ID:
API Key:

#Paulo For new projects the dashboard is not coming up to enable GCM API in https://console.developers.google.com.
Steps to enable GCM:
Create New Project->create API Key->Enable GCM.
To Enable GCM please Navigate to Dashboard tab and search for Google Cloud Messaging-> Click on GCM and enable the API. Please wait for 5 min to get it activate.
Configure the GCM credentials for Push Notification-> register the device and send notification.

Related

AWS SNS - Push for GCM showing as sent from Cloudwatch but not received in Mobile Device

I am migrating from custom Push Notification to AWS SNS. I did the following.
configured AWS SNS Topic
Created Platform Application
created Endpoints
Suscribed endpoints to Platform Application
I am trying the last step for Pushing the Notification using 'publish' API for Ruby. I receive the message_id as response. It also logs as success / delivered in CloudWatch. But the Push is not received in the device.
The device is valid
The device has a valid push token
the device has the application installed.
The message format I tried areas follows
{"GCM"=>{"data"=>"{\"message\":\"message\",\"url\":\"url\"}"}, :default=>"default"}
SNS publish API syntax
client.publish({target_arn: endpoint_arn, message: message.to_json, subject: "SNS test", message_structure: :json})
FYI, Before marking this as duplicate of any other question, please note that i have referred all previous answers and nothing helped me. hence I am raising a new one.
The GCM payload format is updated.
This works for me.
{
"GCM": "{ \"notification\": { \"body\": \"hello....\", \"title\": \"title123\" } }"
}
There is a problem with my message formation. I figured it out by debugging with android . The Push reached the device but it was not in the expected format. So the push was not shown in the device. I was sending
{"GCM"=>{"data"=>"{\"message\":\"message\",\"url\":\"url\"}"}, :default=>"default"}
But the Android system was expecting 'badge' and some other keys in my message. I tried with
{:default=>"default", :GCM=>"{\"data\":{\"message\":\"test\",\"url\":\"https://s3.amazonaws.com/mcds_fulltext/aapg/gsaapgbull/issues/74/android_hdpi/cover_74.gif\",\"registration_ids\":\"arn:aws:sns:us-****-1:*********7:endpoint/GCM/gs*****_gcm/*********************\",\"badge\":\"10\",\"vol\":\"128\",\"issue\":\"10\",\"journal_name\":\"gsaapg\",\"abbr\":\"aapg\"},\"collapse_key\":\"New Article badge\"}"}
Now it works as expected.
This particular JSON might not be appropriate for everyone. But the cause of this issue is the message JSON is not in the expected format for the mobile app. This might be helpful for someone who face the similar issue.

FCM push notifications with Parse Server

This is complicated but I'll try to be as concise as possible. I am using FCM to send push notifications to Android devices. My backend is parse server. I can successfully send pushes from the FCM console to the device. And when I send pushes from parse to https://mybackend/parse/push, it says {"result": "true" } as the response. I have checked the server logs, and it (predictably) says all http post requests to /parse/push were 200 success.
However when sending from parse (using curl or the parse push console), the pushes do NOT show up in FCM console. There is some issue between parse server and FCM then.
In my index.js, I have:
push: {
android: {
senderId: "XXXXX",
apiKey: "YYYYYY"
}
}
I have the keys, and done everything according to here: http://parseplatform.org/docs/parse-server/guide/#push-notifications
what else am I missing? Why can't I get this to actually appear on the device? Any help is greatly appreciated, thanks.
Setting up a Parse Server for an Android app, I remember having to double check this to get it right. The key for me was this: when I logged into Firebase console and selected the app I was working on, and clicked on the gear [or cog or whatever] and then Project Settings, I had to make sure to click on the Cloud Messaging tab and grab the Legacy server key [under project credentials] NOT the web api key that appears on the General tab. Also the sender ID that you want to use appears on that page.
I'm not sure when they will deprecate the Legacy server key, you might try the Server key instead, but definitely make sure you get the info off of the Cloud Messaging tab.
I don't know why FCM (and APNs) don't send a different message when the key (or cert) is not set up right [that would be more developer-friendly at least] and instead just send a 200 but my guess is that they evaluate the key [or cert] after receiving the intended notification and sending a response.

FCM Notification is not working If i send it by using ARC ( Advanced REST API )

I integrated the push notification system with Firebase in my project and it's working well except one thing.
If I try to send a notification from Firebase console, using Device Token & Topic, the notification shows in device.
If I try to send a notification from ARC ( Advance REST CLIENT) using Device Token, the notification shows in device.
If I try to send a notification from ARC ( Advance REST CLIENT) using my topic, NOTHING HAPPENS.
Requested URL : https://fcm.googleapis.com/fcm/send
RAW headers :
Content-Type: application/json
Authorization: key=AIz.....
RAW PAYLOAD :
{
"data":
{
"employeename":"kumaran","empid":"234444"
},
"to":"/topics/bmmembers"
}
Response Header
Status : 200: OK
JSON :
{
"message_id": 6536474446058224000
}
But my device not received any notification and checked Logcat whether any json arrived in client end, but not received.
Any idea and how we need to resolve this issues.
This is my trial and error type of a "Solution found for this Issue":-
Issue found is "The Quota for the particular Server-key or credential or the whole Google API Account itself might have been expired or used the limit. "
Below i have explained how i once again successfully received FCM Notifiaction with Image for the same Android App.
ISSUE:-
I was unable to send FCM push notification (with image) from Advanced REST Client, by using the Android key generated from Google API console in my very old created Project (Eg: My Project; that has 5-apps and its credentials).
I tried sending the Post request from ARC client many time but dint receive any single FCM notification in my Android Mobile.
SOLUTION I FOUND WAS:-
1a. I deleted the credentials (API key, server key,web key, OAuth key etc) in Google API console related to that particular app (Eg: FCM App1).
1b. Also i went to Firebase console and deleted the particular app in its project also.
Finally now the App (Eg.FCM App1) doesn't contain connection with
1.Google API console and with
2.Firebase Console.
1c. I also deleted the "google-services.json" file from the Android studio->Project folder.(If you are unable to delete this, try executing File->'Invalidate cache and restart' option and then retry deleting it. It will get deleted.)
Next, freshly
I created a new gmail account, and opened a new Google API Account, further opened a fresh new Project in that Google API Account (Eg: My Project1).
Next, I went to Firebase console signing in with this newly created Gmail acccount, opened a fresh new Project, selected "Add App" and selected "Android".
-> entered my package name, SHA1 key and Added the App.
-> Also downloadedthe new google-services.json file and added again in the Project folder in Android Studio.
-> And followed everything as per previous procedure.
==> Finally I got the fresh ""Server-Key"" in the new Google API console. Copied this server-key and pasted in Advanced REST client at place Authorization:key=AIzaSyAJzs-DDD......etc.
=> added the correct TokenID freshly created for this App from Log.
===> Pressed SEND button in the ARC, and WOOOOWWWW....
within few seconds I GOT THE FCM NOTIFICATION WITH IMAGE IN MY ANDROID MOBILE EVENTHOUGH MY APP WAS IN BACKGROUND OR COMPLETELY CLOSED at that time....!!!

Google Cloud Messaging

I downloaded the GCM project from git and i was able to start the server (app engine for java) and also compile the client apk on the device. On startup the device successfully registers with the server and I can see the registration id when i go to
http://myserverip:8080/_ah/admin/.
The problem is when i hit the 'Send Message' button there is a message 'Single message queued for registration id ' and it doesn't do anything.
Below is a screenshot of the error i noticed on the terminal. Am i missing something. Any help is appreciated. Thanks.
.
By the screenshot - You are getting a 401 (unauthorized) status code - you are missing the API Key.
Look in the code you downloaded for the place (it will probably be some string whose current value is something like "ENTER_YOUR_API_KEY_HERE") in which you should enter your API Key which belongs to the API Project whose ID you are using at the Client app as sender ID when you register to GCM.

GCM android, Push Notifications not being recieved

I am working on an android app that will recieve push notifications from the GCM server.
I am using php as the 3rd-party server.
I've a few questions.
When I send request to gcm server from my php script it gives me the following response
{"multicast_id":8799227316277290616,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1341388064110557%5d17b789f9fd7ecd"}]}
Now the response seems fine but you can see a % sign in the message_id. Is that ok? if it's not than how am I able to recieve the correct message_ID?
When I use json_decode in my php script and echo this multicastid it gives me something like this
8.7992273162773E+18
and I am sure it will give the same type of value when I'll echo message_id also. So why it is not echoing the correct value?
My last question is that when I send this request which seems right and open my android application there is no notification there. Is it caused by the above errors or there is some other problem?
I had a similar issue with C2DM. The reason was that the android app name was not the same for which I requested the quota. It got fixed once the corrected the package name.
In my case, android application was not running so the push notifications can't be received. I started the app and then I could receive messages.

Categories

Resources