I developed an App that receives push notifications from Google Cloud Messaging, messages are sent to broadcast from a server in php through the procedure CURL. Everything is working fine but a device (Android 4.3) a few days does not receive notifications from GCM.
Question: Is there any way (in PHP) to reclaim such registration id are still valid or need to be renewed?
I know the id registration must be renewed when the app is updated or uninstalled and then reinstalled it in this case was not made any changes.
In this device other notifications arrive correctly (whatsapp, sms).
For my app does not have disabled notifications.
I have not updated or uninstalled the app for groped to understand whether the problem is the device or something more obscure.
Now GCM return this (not error):
{"multicast_id":6846627542248171696,"success":3,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1442178661471816%5ed68546f7f47ecd"},{"message_id":"0:1442178661471814%5ed68546f7f47ecd"},{"message_id":"0:1442178661472121%5ed68546f7f47ecd"}]}
The DEVICE not receive push notification is 3 but CURL operation return true.
Do you have any suggestions?
I have verified that the problem was related to the device and not the Bees google for the non-receipt of the message.
An operation CURL but can not return the entire state of the message because of the fact that it is a synchronous operation. I noticed from the console that can pass several minutes before the device returns the code Accepted.
The only way to confirm the message was received by the device seems to be an asynchronous operation with an appropriate Java server.
Related
I have a Xamarin Forms application where we're using Azure Notification Hub to send messages to both Android and iOS devices.
Whenever someone logs into the application a record is created (or updated) for that device. Various information about that device is stored: who it belongs to, installation id, token, etc.
We then call the hub method CreateOrUpdateInstallationAsync() for that device's installation. In the case of a new install or cleared data we will be passing in a new installation to Azure Notification Hub to create the installation. In the case of an existing installation we're simply updating the tags so that the correct user will be notified when a message is sent.
This all seems to work as expected. After the call to CreateOrUpdateInstallationAsync() we will see both a Native and a Template registration in the hub for a given installation id. I can log in and out of the application and those device records are updated in the hub. I can see the tags change.
However, for some reason, some Android devices will stop receiving notifications. Sometimes this is immediate. That is, right after the app is installed and the device is registered with the hub, it can't receive messages. Other times it could take up to 24 hours or so, but a device that was receiving messages will suddenly stop.
If I use the Azure Portal to try and directly send a message to the broken Android device it tells me that there are "no matching targets". If I use the Firebase console to send a message to the broken device the message is never received.
iOS never seems to have an issue.
I'm unsure how to proceed. It's almost as if the FCM token is invalid at some point. From what I've read the only time it really should become invalid is if the app is newly installed, the data was cleared, or the device was restored. But this invalidated token seems to happen immediately after install or after a day or so of previously receiving notifications without issue.
If this is the case, is there some way I'm supposed to be aware of this when sending a template message through the hub?
I am trying to figure out how Firebase connect to specific devices and send message to it. I now how to use Firebase and send notification to registed devices from my backend server but i don't know how is it working internally. Is firebase severs using persisted connection between device and server? What kind of tehnology is it using?
For now i am mostly interested in Android devices and how firebase wake up device even with background tasks restrictions.
FCM is able to wake a device because the message is actually received by software components that come with Play services, which operates with elevated privileges. Play services can choose to wake the device and deliver the message to the target app.
The FCM software in Play services keeps a persistent socket connection open to its backend under normal circumstances. If it gets connection is dropped, it has logic to reestablish the connection without taxing the battery too much.
I tried to explain how GCM works in my answer here. The internal working principle of Firebase is similar in my opinion.
When you are installing an application which has the Firebase SDK set up in it, it gets a push registration ID from Google server. Usually, you save the push registration ID in your server as well. Hence, when there is a situation for sending a push notification, your server uses this push registration ID to generate a request to the Firebase server for sending a push notification to your device.
Now let us think of the receiver part as well (i.e. your device). In my opinion, in newer versions of Android allows a JobScheduler to check repeatedly for push messages from the Firebase server and if there is one, the device notifies the corresponding application and the application then generates the push notification.
Hope that helps!
My app is using Google's C2DM (push notification) to notify users about new activity from friends. Once they install the app I register the device with C2DM servers and store user's phone number. So I know that the user is using my app and I can send him/her the push notifications. But what happens if users uninstalls my app, is there a way to catch it in my app? Or the only way is to catch an error on my server when I send a C2DM and it's unreachable, then mark a user as inactive?
I would love to notify users when their friends are using an app and when they no longer do.
What's is the best solution for this scenario?
The GCM documentation explains this situation here:
https://developers.google.com/cloud-messaging/registration#how-uninstalled-client-app-unregistration-works
"An application can be automatically unregistered after it is uninstalled from the device. However, this process does not happens right away, as Android does not provide an uninstall callback."
Basically when GCM tries to send the next push notification, the device will tell GCM the receiving application was uninstalled.
As for notifying friends that their friends aren't using the app any more, GCM will send a NotRegistered error to your notification server when this failure occurs; it won't be immediate, but could you use that?
Unfortunately the ACTION_PACKAGE_REMOVED intent will be sent out to all receivers except for your own. This is confirmed here.
Some questions for your C2DM plan, since I'm not very familiar with it. If the user just leaves their device off for a long period of time, will that trigger the error condition you use? How does C2DM actually report an "unreachable" device? Is that a condition that only occurs when it attempts to send the push notification and fails or is it when it somehow determines it reaches the device but fails to be handled properly? Obviously in the second scenario your plan would work, but I can see some "false positives" occurring otherwise.
Older SO question for reference: android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package
Yes, but it is quite hacky.
The method is based on the fact that the first thing android does when uninstalling your app is deleting your data file. So you could use a file watcher to detect the deletion.
Also you need to write this in native code. If you write your code in java, your app will be uninstalled before it could execute any code.
please see this demo : https://github.com/sevenler/Uninstall_Statics
Google C2DM service is working in passive mode when it comes to detecting uninstalled applications.
First push notification after uninstalling your application (without unregistering from C2DM!!!) will NOT return any error in response. However, the second push notification will return an "invalid registration" or "not registered" error codes where you can realize the application was uninstalled.
The reason is that C2DM servers return the response code immediately and only then tries to push the client. When client respond that an application was uninstalled, it is deleted from C2DM servers. Next push attempt will return an error code immediately.
I have some points to tell you ,
Android community recommends you to use GCM instead of C2DM as it's no longer available.
In android there is no way for applications to get itself notified that app is getting uninstalled.
in GCM if you want to stop sending messages to uninstalled apps you can refer this
When you send messages to GCM from your server you will get response string.In that if you are getting error as "NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device or it does not have a broadcast receiver configured to receive com.google.android.c2dm.intent.RECEIVE intents."
I know only one way with server response 200 with "NotRegistered" message in body.
NotRegistered — The registration_id is no longer valid, for example user has uninstalled the application or turned off notifications. Sender should stop sending messages to this device.
Look into this GCM doc:
GCM Unregistration
You should never unregister your app. This is taken care from server side.
To detect app uninstallation using Google Play Services, you can use the App Uninstallation Reporting API. This API allows you to receive notifications when your app is uninstalled by users. #ThanksChatGPT
I am working on a client site where we are using Drupal for the backend and have recently implemented the Push Notifications module to handle messaging to users of the clients app from the App/Play stores.
All has been working fine for a number of weeks with tests performed and many messages sent.
Now when attempting to send notifications the system returns the 'success message':
Successfully sent 26 iOS push messages (attempted to send 26 messages).
Successfully sent 0 Android push messages (attempted to send 106 messages).
I came across something on the Android Developers forum at http://developer.android.com/about/versions/android-3.1.html#launchcontrols and at https://groups.google.com/forum/#!msg/android-gcm/MqVlA3Sj26c/uO-ttsXOyy0J and https://www.parse.com/questions/problem-with-push-notification-where-android-apps-force-stop.
From what I can understand they are saying that after a user force-stops an app that notifications are not received until the next time the app is started.
If this is correct then my 'attempted' messages count does not mean that the push/send is broken on the site but is likely that users uninstalled the app or have force-closed it.
Is this correct?
Would love to hear anyones thoughts or recommendations.
From what I can understand they are saying that after a user force-stops an app that notifications are not received until the next time the app is started.
Assuming that this system is using GCM, that is a correct assessment.
If this is correct then my 'attempted' messages count does not mean that the push/send is broken on the site but is likely that users uninstalled the app or have force-closed it.
You would have to ask the authors of whatever it is that you are using that question. It could be that there is some configuration problem whereby the system is incapable of reaching Google's servers, for example.
My app is using Google's C2DM (push notification) to notify users about new activity from friends. Once they install the app I register the device with C2DM servers and store user's phone number. So I know that the user is using my app and I can send him/her the push notifications. But what happens if users uninstalls my app, is there a way to catch it in my app? Or the only way is to catch an error on my server when I send a C2DM and it's unreachable, then mark a user as inactive?
I would love to notify users when their friends are using an app and when they no longer do.
What's is the best solution for this scenario?
The GCM documentation explains this situation here:
https://developers.google.com/cloud-messaging/registration#how-uninstalled-client-app-unregistration-works
"An application can be automatically unregistered after it is uninstalled from the device. However, this process does not happens right away, as Android does not provide an uninstall callback."
Basically when GCM tries to send the next push notification, the device will tell GCM the receiving application was uninstalled.
As for notifying friends that their friends aren't using the app any more, GCM will send a NotRegistered error to your notification server when this failure occurs; it won't be immediate, but could you use that?
Unfortunately the ACTION_PACKAGE_REMOVED intent will be sent out to all receivers except for your own. This is confirmed here.
Some questions for your C2DM plan, since I'm not very familiar with it. If the user just leaves their device off for a long period of time, will that trigger the error condition you use? How does C2DM actually report an "unreachable" device? Is that a condition that only occurs when it attempts to send the push notification and fails or is it when it somehow determines it reaches the device but fails to be handled properly? Obviously in the second scenario your plan would work, but I can see some "false positives" occurring otherwise.
Older SO question for reference: android not receiving Intent ACTION_PACKAGE_REMOVED in the removed package
Yes, but it is quite hacky.
The method is based on the fact that the first thing android does when uninstalling your app is deleting your data file. So you could use a file watcher to detect the deletion.
Also you need to write this in native code. If you write your code in java, your app will be uninstalled before it could execute any code.
please see this demo : https://github.com/sevenler/Uninstall_Statics
Google C2DM service is working in passive mode when it comes to detecting uninstalled applications.
First push notification after uninstalling your application (without unregistering from C2DM!!!) will NOT return any error in response. However, the second push notification will return an "invalid registration" or "not registered" error codes where you can realize the application was uninstalled.
The reason is that C2DM servers return the response code immediately and only then tries to push the client. When client respond that an application was uninstalled, it is deleted from C2DM servers. Next push attempt will return an error code immediately.
I have some points to tell you ,
Android community recommends you to use GCM instead of C2DM as it's no longer available.
In android there is no way for applications to get itself notified that app is getting uninstalled.
in GCM if you want to stop sending messages to uninstalled apps you can refer this
When you send messages to GCM from your server you will get response string.In that if you are getting error as "NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device or it does not have a broadcast receiver configured to receive com.google.android.c2dm.intent.RECEIVE intents."
I know only one way with server response 200 with "NotRegistered" message in body.
NotRegistered — The registration_id is no longer valid, for example user has uninstalled the application or turned off notifications. Sender should stop sending messages to this device.
Look into this GCM doc:
GCM Unregistration
You should never unregister your app. This is taken care from server side.
To detect app uninstallation using Google Play Services, you can use the App Uninstallation Reporting API. This API allows you to receive notifications when your app is uninstalled by users. #ThanksChatGPT