sending fcm notification messages to multiple android devices by registration_ids parameter - php

I want to send notifications to multiple android devices(where same app is installed) by fcm from php server side by calling this url -
https://fcm.googleapis.com/fcm/send
I checked sending messages to device groups but my requirement is such that there will not be definite devices to which i will send messages because i am going to do it in a hourly cron job, and each time a cron job runs it will send notification messages to different different devices according to requirements. or can it be done in another way?
But i am thinking to use "registration_ids" parameter instead of "to" parameter, details of these fields here in the Downstream HTTP messages section. In this registration_ids field i will put all required device registration tokens in array. Now my question is after receiving message in android device can the message be parsed in the android app sdk codes?. i am in a bit of doubt as in this documentation there are no mentions of registration_ids parameter when sending messages to multiple android devices. Please assure me. And furthermore, will the message be sent when android app is in background?!. Please don't write one line, provide some examples if possible.

In the documentation for building requests to send to multiple devices you will find an example of passing multiple FCM tokens in a single call to the FCM API in the tokens parameter (in Node.js) or by using a HTTP batch request with multiple subrequests (in the REST API).
If you're having a hard time making this work, posting a question that shows what you tried increases the chances that someone can help making it work.
Yes, the message is sent regardless of whether the app is in the foreground, or in background. Whether the notification is actually shown depends on many more factors, many of which are outside of your control (such as the Android version, device maker/OEM, and the user settings).

Related

How to send FCM Notification to a list of specific device tokens using the v1 API

I want to use the new FCM HTTP v1 API, which is documented here
FCM HTTP v1 API Documentation, to send a notification to multiple devices at once, but without using topics, or groups (let's say I want to send a notification to 10 random winners of some lottery). I know that in the previous version (Legacy FCM HTTP Protocol), this was possible by using the registration_ids parameter, but I don't see anything similar in the current API. Am I missing something? Is there a way to do this without using the legacy API?
There is currently no other way to send to multiple tokens besides using topics for FCM v1.
In your mentioned use case, if I'm using v1, I would probably go at something like, after selecting the winning tokens, you subscribe them to a topic like winningTokens<date_here> then send the message.
For other use cases, the best way to send to multiple devices via v1 API depends on your application. For example, the accepted answer would not be a good solution for a private chat application where another user can guess the topic name and evesdrop on the conversation by subscribing to the topic. In that scenario iterating over the device list and making multiple send calls to a single device would be better.

Do I have any way or another service to push notification that have different message (payload) to different tokens in One http request?

My purpose: One Push Notification to iOS app, badgeNumber on device need to update based on each device's badge increment.
We knew that we can send only one message (payload) to different tokens
in iOS, We cannot update badge number even we receive remote notification when App is forced to close from background.
I want to use above method to send Different Badge Number to each device, since I get badge number for device from my DB Server.
I used FCM for iOS push notification
for Server-side, I use PHP
Some discussion(Android GCM - Send different payload to each user in registration_ids array )
said it's not possible, so is there any way or paid service?
Some said we need to send each payload to each device tokens using loop. Example, I have 1000 tokens, will APNS block my future request?
For my app's usage: around 50 push/day
Thank for your contribute.
Some notes to your comment:
You can update badge if the application is dead, but it cannot be a silent notification, if silent it will simply ignored. Using a "normal" notification with badge in payload you can, in fact update it even killed manually.
You must keep in database all the device token with user associated, and send individual notification, you can't send bulk message with different content (in this case with different badge).
No, it will not block, you can send for each one:
This is from another forum but can be used as reference:
According to the "Push Notification Troughput and Error Checking" section of this Tech Note:
https://developer.apple.com/library/ios/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG44
"There are no caps or batch size limits for using APNs."
"If you're seeing throughput lower than 9,000 notifications per second, your server might benefit from improved error handling logic."

Sending push messages to all open chrome browsers via GCM

I am trying to develop a web site which will send push notifications to all users currently watching it. I found some tutorials on how to send pushes to myself using GCM for Chrome and they are working fine,
(https://github.com/gauntface/simple-push-demo)
but I cannot understand how to send pushes to every user who is currently on my site and allowed to receive them. As far as I understand I need to collect their browser IDs when they subscribe
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({ userVisibleOnly: true })
.then(onPushSubscription)
but I cannot find how to get and store them (perhaps in MySQL DB with PHP code) and after that how to send a push to everyone (probably to iterate over all browsers IDs in my DB and send pushes to everyone separately with cURL requests). On my site I have code which uses ServiceWorkers and handles users subscription but everything is working for me only. Noone who is else on a site does not receive any notifications. Any help would be appreciated.

Send gcm messages to different application activty

Im new to android application development and im developing an app that uses GCM messaging. This app registers to my php webserver. I follow some tutorials about gcm but im really confused. This application has 3 activities:
NewsActivity.java - displays new information and special topics.
MemoActivity.java- displays memo.
3 EventsActivity.java - displays important information about special events.
My problem:
How can the server send gcm messages to specific android activity. For example i want to send gcm message to NewsActivity.java ONLY which means that the message will only be displayed in that specific activity?
How can the app determine if that message can only be displayed on specific activity?
I don't know where to start. Any information you can provide me would be greatly appreciated. Thanks.
GCM Server sends the message to the app. It is received in the Broadcast receiver. There you can find which of your activity is visible by setting a flag to some value in every activity or by other means. Or follow this dealing with received gcm push notification in different activities?

Send Push notification to specific Users

I am trying to develop an android app that verifies a transaction initiated from a browser on a PC. I want the server application to push a notification of a new transaction to the app so the user can confirm to complete the transaction. The tricky bit is the transaction is specific to a particular person (I'm using this as an alternative to sending an SMS for example). Can anyone help on how to go about this? Is it possible to do this with C2DM or GCM?
Using Android GCM is advisable. The complete reference to GCM is available at
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
Step by step GCM development is given in there. It is really very helpful. Hope this is helpful to you.
The critical thing you need to keep in mind before making a decision is that when you are using GCM, you need to keep a track of the users by keeping their GCM_ID in your database. You can add a gcm_id column to your users table for this and whenever the user opens your app, the gcm_id should be updated in your database. The gcm_id of the user's phone can change, from the official docs:
Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times
GCM push notifications wont be able to reach your users mobile phone all the time,especially if his phone is not connected to internet or switched off.You are using this for transactions etc, so I assume that the notifications must not fail. You should keep a check in your web application to send an SMS or notify the user that this has failed. You should get a response from GCM to your server through which you can identify a failed case.

Categories