I'm trying to send Push Notifications via C2DM / GCM to an Android Application via PHP.
No matter which i use, i keep getting the following :
For GCM :
{"multicast_id":7672049265453358197,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
For C2DM : Error=InvalidRegistration
After reading allot about this issue all day I'm still clueless as to why this is an InvalidRegistration as if i take the registatoin_id and use it to send a test push message via Urban Airship it works.
Notice that this is not an auth issue as i get a [http_code] => 200 back from google and not 401.
If i send an empty registatoin_id or even omit just one char from it the error message changes to "MissingRegistration".
Any help would be appreciated.
If you copied the apid from UrbanAirship then that's the problem:
http://docs.urbanairship.com/reference/glossary.html#term-apid
Airship Push Identifier
APID
APIDs identify devices with transient registration IDs, such as Windows devices.
These identifiers are version 4 UUIDs, and are 36 characters long, including dashes.
You need to get the device information from http://docs.urbanairship.com/api/ua.html#get--api-apids-(APID) in the "gcm_registration_id" property. That's the registration id needed.
It seems you need to then keep track of that registration id as it is transient as suggested by UrbanAirship. But that's another topic.
Related
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).
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."
I am using Google Cloud Messaging from last one year with PHP as server side script and it is working fine on all app until I hasn't sent notification to one of the may application for one month then after that while sending notification to same app I gets blank response like
{"status":[],"0":"\n\n
so I assumed that google may have deactivated my API key so I regenerated my API key from developer console and replaced regenerated key with old key on server side and at that time it had worked I was able to send message again but after two week again I am getting blank response like given above and this time I was sent notification to same app everyday.
From this related SO question. It suggested to make sure that it's retrieving the POST variable in your PHP code.
Try to replace this:
$message = array("Notice" => $_POST['message']);
with:
$message = array("Notice" => "testing");
You can also check on this tutorial and thread on how to integrate GCM in PHP backend properly.
Problem is solved after importing project into firebase.
Server API Key is auto generated by google services and after using those keys on server site i am able to send notification.
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?
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.