Creating Notifications onesignal not language - android

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

Related

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

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.

FCM returning response for single registration id when targeted for multiple registration_ids

I am writing app server side of FCM implementation where it will send a particular message to Multiple devices.
I am using registration_ids as key and JsonArray with multiple recipients, however the response returned is showing only for one recipient as follows
{"multicast_id":7185150746202793615,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
I am not sure whether to set any property in firebase console to enable multiple registration ids acceptance.
Following is the request json :
{
"registration_ids":[
[
"eU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i",
"FERTeU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i"
]
],
"notification":{
"title":"Hello FCM",
"text":"Notification details"
},
"time_to_live":3600,
"priority":"HIGH"
}
And the response for this request is
{
"multicast_id":7697036511101523125,
"success":0,
"failure":1,
"canonical_ids":0,
"results":[
{
"error":"InvalidRegistration"
}
]
}
The Problem was with this Json formation for request. It has to be
{
"registration_ids"[ "eU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i",
"FERTeU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i" ],
"notification":{
"title":"Hello FCM",
"text":"Notification details"
},
"time_to_live":3600,
"priority":"HIGH"
}
The extra square brackets ([ ]) is causing the issue.

GCM not using data from JSON payload in the notification

I am sending the following JSON through GCM (Google Cloud Messaging) but I have not been able to get the right response data through the Client. I get a push notification response, but the title is the App's name, and the texts reads: "message" so I can't display my notification properly.
Here is the JSON that I am trying to send:
{
"to": "somekey",
"notification": {
"body":"Test",
"title":"Test"
},
"data": null
}
I think that your problem is on the key-values of the payload of your message.
As you can see at GCM Server documentation, the payload can be set using two different keys:
data: This parameter specifies the key-value pairs of the message's payload.
notification: This parameter specifies the key-value pairs of the notification payload.
You should use the data key and set inside the payload of the notification. Once send, you can print the result of the notification received and see that there are the right payload inside the data key.
Your message should be like the following JSON data:
{
"registration_ids" => "some_target_device_id",
"data": {
"title": "My title",
"message": "This is the message!",
}
}
Authorization: key= AIz......#GCM project key
{ "data": {
"title": "Summer Offer.",
"message": "Click to visit the offer."
},
"to" : "Device Token"
}

GCM push notification message outside data dictionary

Is there a way to retrieve the key "message" on the device when sending notification to GCM.
{ "collapse_key" : "score",
"data" : { "k1" : "v1" },
"message" : "Hello World!",
"registration_ids" : [ "DEVICE_REGISTRATION_ID_GOES_HERE" ]
}
From the intent.getExtras(), I'm able to receive the following keys "collapse_key", "from", "k1" and their corresponding values as well. However I do not get key "message". If I do not add anything in the "data" dictionary, I still get push notification without "k1" (as expected).
Push to GCM does not result in errors. Does GCM drop keys not mentioned in "data" dictionary?
Yes the way you have it won't work. Anything you want to add, make it part of the data object:
{
"collapse_key": "score",
"data": {
"k1": "v1",
"message": "Hello World!"
},
"registration_ids": [
"DEVICE_REGISTRATION_ID_GOES_HERE"
]
}

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