I have used the loopback sample application "loopback-3.x" given on:https://github.com/strongloop/loopback-example-push. The correct server key was given in config, then created an application and registered a device with that application. Then I tried sending a push notification with "notifyById" method. The console shows a succes message like:
loopback:component:push:provider:gcm Sending message to ["devicetokengiven"]: {"params":{"timeToLive":3600,"data":{"message":"sfwsed","messageFrom":"sdefsdf","badge":2}}}
loopback:component:push:provider:gcm GCM result: {"multicast_id":multicast_id,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:23423555466%24324434354"}]}
It seems to be a success, but the device doesnt get any push notification. What could be the issue? Any help would be appreciated! Thanks!
Unfortunately their last release simply doesn't work with FCM. However, in their last commit they have a change which requires an object with the attributes (messageFrom and alert) and then they convert these att to body and title. Moreover, there is a PR where someone adds another notification's attributes, but I don't think it will be merged soon.
Solutions:
Reference your module to their last commit: "loopback-component-push": "git://github.com/strongloop/loopback-component-push.git#dce16d9be30d80e258c2ac5e3dc1f74276f2b0cd"and send {messageFrom: "your title", alert: "your body"}
or
Use a simple FCM node module or even a HTTP request. Will make your life much easier.
Related
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.
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.
I'm trying to send the following payload to a specific device (which is why I'm using the registration_ids) via Test Send on Azure's Notification Hub, but I'm getting a bad request error.
{
"registration_ids" : ["2670873167838193734-9582072870486547213-1"],
"data":{"message":"Hello World!"},
}
I'm not sure why since I checked the formatting and it looked fine to me based on other sources I saw.
Does anyone have an idea on what's happening?
EDIT:
Here's how I eventually managed to send a notification to a specific user:
on the client side (Java), I replaced the line
hub.register(regid)
with
hub.register(regid,"myTag")
Where "myTag" can be any other string tag you want. That way you can enter the word myTag in the 'Send to Tag' on Azure's Notification Hub and verify that you received the notification on your device.
Also, if you want to send the notification from the server side (C#), you'll need to add this header to your http request:
request.Headers.Add("ServiceBusNotification-Tags", "myTag");
Hope this helps anyone.
registration_id would not be part of the payload (see https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx request body) although it is part of GCM's payload. To send to a specific device, you will need to tag that device with an id of sorts (e.g. registration_ids) and send to the tag "{registration_id}".
This is due to registration_ids field in the payload. Notification Hub does allow passing the registration_ids in the payload. Notification Hub internally substitute the registration id (before sending to GCM/FCM) based on selected devices.
https://msdn.microsoft.com/en-us/library/azure/dn530749.aspx
Thanks,
Sateesh
I have a Json URL, which contains data about Latest Job Postings, I am successfully parsing the Json URL and able to display the top job postings in my ListView.
But my requirement is to create a push notification, so that whenever a new job is posted, the user should be able to get a notification on device.
I have followed this: http://www.vogella.com/articles/AndroidNotifications/article.html
But I don't know how to get notifications in my case.
Could anyone help me?
Issue:
Give push notification to user's device about the updated data even when application is in background mode.
Solution:
Upon successful insertion of new data in your database (which is going to give updated set of data to your JSON request) , just call the file which send GCM push notification to all your users.
Reference:
GCM docs
GCM push-notification using php server
In context of implementation presented in demo app of 2nd link,
upon successful insertion,you can call send_message.php file,but make sure that $regId and $message should be retrieved from your database
You have created ActionBar Notifications for your app, but now you need to create the ability to receive notifications from a web client, instead of going to find them yourself from the URL.
To create a push notification you would need to have a constant thread (BroadcastReceiver) on the device that is waiting for the notification from the sever.
Google 'Cloud to Device Messaging' is the simplest way to do this.
This is a good link with lots of info on how to do this :
http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android/
If you require these notifications to be displayed on the device even when the application is not running (which seems to be the case from what you describe), you can use Google Cloud Messaging.
You would need a server that would poll the Json URL for updates, and send a GCM message to all the devices where your app is installed once such an update is detected.
Your app would have to register to Google Cloud Messaging and send the Registration ID received from Google to your server.
When your app receive a GCM message, you would create a notification and when the notification is tapped, you would start the activity that loads the data from the JSON URL.
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.