What should the payload be for Android push notifications (GCM) - android

From my understanding of the GCM documentation you basically send whatever data you want as the data field. Then the client receives it and is responsible for handling it and displaying it. Is this wrong? What if like on iOS I just wanted to send a bit of text and have it display? Is there a standard key to use or anything? I'm pretty certain I've been through all the documentation I can find and don't see anything like this.

No, you're right. There are no standard keys like in iOS, it's all up to you seeing as you're the one responsible for the notification management.
Basically, in your BroadcastReceiver you should write the code for displaying a Notification in the status bar. Just parse your JSONObject from the recieved message and show whichever piece of text you may have set.

Related

Firebase: Making multi-lang notifications

My case is the following: a user do something, then my Firebase script in Functions should notify his friends, but it don't know what lang set up for the app of certain friend.
If the Android app in foreground, there is no problem, I simply should send some json in notification payload and then parse it in onMessageReceived using current lang values. But I can't do the same, when the app in background or closed. So it sounds like I have to build multi-lang notifications at the backend, am I right? Any suggestions appreciated.
Searching for hours, I had found pretty good answer. You don't have to store lang constants in backend scripts, because you can manage notification's data even if your app in background or even closed. You just should clear notification field of notification payload. See full answer.

Sending simple data with notification to another app

I'm working on two seperate apps that need at some point to exchange messages, both apps share a MYSQL database, I want the first app to be able to send some data to one of the other app's users (specified by his id, email or phone number ), and this last to be able to reply to the request by accepting or rejecting with a button click.
Now, I don't know what is the best:
Something similar to chat ?Is it possible to extract the necessary data from the rest of the chat message ?
A broadcast.
A push notification.
Or something else ?
Help me please I'm a total newbie, I would use an expert opinion.
What you are describing is basically every other Chat App that exists.
I can only suggest you to read this code example to get an idea how to approach this:
Android Chat Example code

FCM differences between Android and iOS about data messages

I'm using Firebase Cloud Messaging to send data payload and display notification in my Android and iOS apps. I'm integrating this in my iOS app and I'm in front of a curious thing.
Short story:
My notification server only send data messages (I mean JSON messages containing "data" field and with no "notification" field). In my Android app this is not a problem because I receive the message even if my app is in background in my Service implementation and I manually build a notification that I display. But in iOS case, how can I receive message when my app is in background to do the same? I mean if I add a "notification" field to my request I see the notification pop on my screen (when app is in background) and I can get data (located in the "data" field) after a click when my app is in foreground.
But can I have data when my app is in the background to manually display a notification?
Important precision:
The content of the displayed notification should be built app side and not server side because the server doesn't have enough informations, this is why I can't send the "notification" field in my payload message.
Thanks
EDIT: I solve (in part) this problem using this link. Shortly, I enabled both Background fetch and Remote notifications under Background Modes (and added content_available : true in the payload). Then I can process data received in didReceiveRemoteNotification: But now it still one thing: how make it works when my app is killed?
EDIT 2: I found something that could be the thing : that. Modifying the payload of a remote notification implies to handle incoming notifications before there are displayed. I'll try.
EDIT 3: Firebase doesn't support the mutable-content key required to make my solution found at EDIT 2 working. Discussion about that is here. So... Any idea?
I do not think it is possible to trigger "stock" notification on iOS from code the same way you do on Android using NotificationBuilder.
The only option available is to use hybrid messages with both notification and data payloads.
Check their doc for more information on hybrid messages.
On 16/02/14, Firebase added compliance with the "mutable-content" key. So that solved my problem and, I think, many people's problems.
Personal thinking:
I consider that 6 months late for this feature is really too much. I hope that future releases'll be up to date with iOS (as well as Android) releases.

Phonegap PushPlugin with a badge number and grouping feature

I have used pushPlugin to recieve push notification in my phonegap android application. Everything is working correctly. Only issue is when multiple messages are present in the notification bar, the last message overrides the previous message. I would like to group all the messages under the app as whatsApp does.
I tried adding notId parameter and setting it to random number from my server side code. Doing this actually displays multiple notifications but does not group then.
I would also like to know how to add badge number to my app. Basically a number which will tell the user that so many number of notifications are come. As it is in whatsApp (ex. 2 messages received). I have added this plugin to handle that, but I am not sure whether it has to be done in phonegap or will i have to modify java code (plugin) to achieve this.
I know this topic is addressed previously here but there is no answer to it. hence i have raised a new question. Any help would be appreciated.
I do think (although I totally am not sure) that WhatsApp doesn't actually show separate notifications, instead it concatenates the non-read messages on server before sending just one new notification that overwrites the current as you said. For example, if you initially have one message not read causing this notification
WhatsApp
Hey dude!
and then you receive another message, the notification sent is
WhatsApp
2 new messages from 2 contacts
or if the sender is the same contact
WhatsApp
Hey dude!\n
What is up?
You could use the pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);if you only needed iOS support but as it doesn't support the Android for that feature you need to use something else and that plugin you mentioned looks good for it. Seems like it is quite easy to use like this (after it is installed)
cordova.plugins.notification.badge.set(3);

Can I send periodic messages to my Android app users?

Is it possible to make a app on Android such that whoever downloads this app receives a message from me weekly? I want to be the only person who can write on this message board and no one else. If this is possible, where should I start looking for tutorials about doing this sort of stuff?
You can create a RSS/Atom feed for yourself. Your android app can then just sync to this feed. Update the feed as often as you like. If you like this approach I can give more details.
yes , you can send periodic messages see this
in that SendMessage(); function is there so you have to make code for send message to recipient

Categories

Resources