Sending push notifications using post requests(manually)(Parse-server)? - android

with Parse.com I used to be able to send push notifications via simple https post requests, something like:
{
"registration_ids": ["some_device_token_from_the_dashboard"],
"data": { "title": "How are you", "message": "Ok?" }
}
I added a json content type and set Authorization to key=server_key.
Another tool that could be used is: http://www.androidbegin.com/tutorial/gcm.html
Anyway, I'm working with the android SDK v4.13.1 and Parse-server v2.2.16, when I use the dashboard to send push notification to everyone I get the notification, but when I try the post request that used to work with parse.com, the response is:
{
"multicast_id": 8851650859439498656,
"success": 1, "failure": 0,
"canonical_ids": 0,
"results":[ { "message_id": "0:1470077514727128%33b2cdf9f9fd7ecd" } ]
}
It looks like all is find but I don't get the notification at all, btw at the google console I didn't set the IP field so it accepts requests from 0.0.0.0(all interfaces), I assume there something I'm missing here, should the post request be different, what am I doing wrong?, is that a bug or?...
Edit:
Just to clerify, I implement my on PushReceiver that extends ParsePushBroadcastReceiver, and as before when I try to send push via simple post request(using my server-key and registration id) it won't work(the onPushReceive method never called).
POST request details:
My endpoint is https://android.googleapis.com/gcm/send(I did try gcm-http.googleapis.com/gcm/send as well)(https://developers.google.com/cloud-messaging/http for more details), Content-Type set to application/json and Authorization set to key=server_key, the content is given at the beginning of the question.

Related

Creating Notifications onesignal not language

I'm adding the push in an application already published, and I just wanted to change how to send the push without having to send a new update to the application.
Today by amazon we send like this:
{"GCM": "{ "data": { "message": "teste" } }"}
And by your system send thus:
{"GCM": "{ "data": { "message": {en:"teste"} } }"}
Is it possible to send a json in this way?
{"GCM": "{ "data": { "message": "teste" } }"}
Due to actual limitations of OneSignal, the default language is always English ('en').
You can check more details in its documentation here: https://documentation.onesignal.com/docs/language-localization

Not able to send push notifications in ionic getting error:APNS_BAD_DEVICE_TOKEN

For last two days I am unable to send push notification on Both on Android as well as on iOS. Two days back everything was working fine. But while checking my uuid, I am getting blank data array in the response from the url mentioned below
https://api.ionic.io/push/notifications/9ee3e2f9-4226-486b-a01e-ade1559cba1f/messages
response of this url is mentioned below:
{ "meta": {
"status": 200,
"request_id": "65683037-3aef-4348-c3ec-b8bd06cca55b",
"version": "2.0.0-beta.0" }, "data": [] }

Firebase Cloud Messaging - "success" and "failure" in response JSON

I use Firebase Cloud Messaging to deliver notifications to my Android client apps, each notification should be sent to a single device according to its registration token.
Each time I send a notification via https://fcm.googleapis.com/fcm/send, I receive a JSON response like this one:
{
"multicast_id": 108,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{ "message_id": "1:08" }
]
}
I find success and failure redundant - don't they mean the same thing? Should I check both of them to be sure everything is fine? Is it always true that success != failure?
As described here :
success - Required, number of messages that were processed
without an error.
failure - Required, number of messages that
could not be processed.
You get :
"success": 1, which means 1 message was processed successfully and
"failure": 0, which means no error
total number of requests to FCM server = success + failure
Sum of success and failure makes up the total number of requests. In your case, when you're sending to one user only, it doesn't matter. But when you're sending to multiple users, you can get success and failure and sum them up to know how many requests were sent to FCM server.
Ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream
As described above in response I got:
{{
success: true,
messageId: someid,
},
{
success: false,
error: [yourerror],
},
successCount: 1,
failureCount:1,
}
In my case, 1 fcmtoken expired, so 1 failure.
successCount means how many of the notifications were sent and failureCount are the tokens that caused the error.
Add the notification parameter along with data and registration_ids.
{"notification":{"title":"","body":""},"data":{},"registration_ids":["acaxdYt5464262hghdsd*****"]
}

Android, abort notification comes from parse push

I check the JSON that is comming from parse push that I'm sending from parse push and if it match with my filter, I save it in database otherwise if it doesn't match, I want that user don't see it's notification at all.
checking and saving are working good, but I can't dismiss (abort) it when it's not matched.
I tried this.abortBroadcast(); at onReceived and also onPushReceive but it doesn't work.
You should not abort it, just you have to use a correct JSON format, like this:
{
"data": {
"message": "Hello! World.",
"title": "my title"
},
"is_background": false
}
is_background determine whether to show notification or not.

Is there a way to add "hidden" data to a GCM (android push) notification?

Is there a way to somehow add some data to the Android push notification by the server side?
So I can parse the added data in my app and do some actions related to it, like an Id or something like that.
Of course it must be "hidden" so the simple message is not the way I want it.
Of course there is. Every piece of data you put in the message payload can be "hidden". As the developer of an Android app, it's your decision which parts of the payload are displayed to the user and which are not.
In the server side you decide which data you wish to put in the payload of the GCM message (inside the data dictionary), and you decide what to do with it in the application.
{ "time_to_live": 108,
"data": {
"message": "you can display this message",
"id": "123456",
"some-hidden-field": "some-hidden-value"
},
"registration_ids":["4", "8", "15", "16", "23", "42"]
}

Categories

Resources