Send gcm message to only installed user - android

I want to send gcm mesage to only installed user or devices.
Active (installed) user is only 20% of gcm-registerred users in my app.
Maybe 7~80% is delete my app.
I want to send ony installed users, not uninsatlled user.
It is possible to send to only installed users? or to get event that user uninstall my app?

Send your message to all users. If a user has uninstalled the app, GCM will notify you in reply to your push message. You can then remove those users from the database.
You can see a description of this process here
The end user uninstalls the application.
The 3rd-party server sends a message to GCM server.
The GCM server sends the message to the device.
The GCM client receives the message and queries Package Manager about whether there are
broadcast receivers configured to receive it, which returns false.
The GCM client informs the GCM server that the application was uninstalled.
The GCM server marks the registration ID for deletion.
The 3rd-party server sends a message to GCM.
The GCM returns a NotRegistered error message to the 3rd-party server.
The 3rd-party deletes the registration ID.

if you send gcm message then only install user get this any user who have alredy uninstall your app not get nofication dear
try to send to all user its not an problem

Related

GCM: Handling Old RegistrationId when user uninstall the app

Here is the scenario of the problem I am facing right now. I have a web app that holds all the registration id of devices that connected to my server. On my android app. Every time the user logs in, I send request for registration id to google, forward to my server, then the server saves it and link it to the user. When a user logs out from my app. My app sends a request to the server to destroy the authentication code and registration id. The problem was, when the user uninstalls the app and a reinstall it again, his old registration id retains on my server. So when he logged in on his same phone. the app registers the new registration id to my server, when the server pushes a notification, that user would receive multiple notification depending on how many times he uninstalled the app. What is your work around on this one?
From the Official Documentation:
A client app can be automatically unregistered after it is
uninstalled. However, this process does not happen immediately. What
happens in this scenario is:
The end user uninstalls the client app.
The app server sends a message to GCM connection server.
The GCM connection server sends the message to the GCM client on the device.
The GCM client on the device receives
the message and detects that the client app has been uninstalled; the
detection details depend on the platform on which the client app is running.
The GCM client on the device informs the GCM connection server that the client app was uninstalled.
The GCM connection server marks the registration token for deletion.
The app server sends a message to GCM. The GCM returns a NotRegistered error message to the app server.
The app server should delete the registration token.
Note that it might take a while for the registration token to be completely
removed from GCM. Thus it is possible that messages sent during step 7
above get a valid message ID as a response, even though the message
will not be delivered to the client app. Eventually, the registration
token will be removed and the server will get a NotRegistered error,
without any further action being required from the app server.
Check this our: Downstream messages response codes
Unregistered Device
200 + error:NotRegistered
An existing registration token may cease to be valid in a number of scenarios, including:
If the client app unregisters with FCM.
If the client app is automatically unregistered, which can happen if
the user uninstalls the application. For example, on iOS, if the APNS
Feedback Service reported the APNS token as invalid.
If the registration token expires (for example, Google might decide
to refresh registration tokens, or the APNS token has expired for iOS
devices).
If the client app is updated but the new version is not configured to
receive messages.
For all these cases, remove this registration token from the app server and stop using it to send messages.
Refer Official document.
You have to check this on your server. You cannot do it from the application code since there is no way of knowing when the user is uninstalling the application.
when you send a push notification, GCM will check if the user has your application, if the user has uninstalled the application GCM will note the same and inform you as part of reply for the push.
EDIT - From GCM docs
How uninstalled client app unregistration works
A client app can be automatically unregistered after it is
uninstalled. However, this process does not happen immediately. What
happens in this scenario is:
The end user uninstalls the client app.
The app server sends a message to GCM connection server.
The GCM connection server sends the message to the GCM client on the device.
The GCM client on the device receives the message and detects that the client app has been uninstalled; the detection details depend on
the platform on which the client app is running.
The GCM client on the device informs the GCM connection server that the client app was uninstalled.
The GCM connection server marks the registration token for deletion.
The app server sends a message to GCM.
The GCM returns a NotRegistered error message to the app server.
The app server should delete the registration token.
Note that it might take a while for the registration token to be
completely removed from GCM. Thus it is possible that messages sent
during step 7 above get a valid message ID as a response, even though
the message will not be delivered to the client app. Eventually, the
registration token will be removed and the server will get a
NotRegistered error, without any further action being required from
the app server.
This can be done on your server side code.
While inserting requested data to your GCM table, check if your user id is already in table? if yes simply replace whole row with new data. else insert fresh new data into table.
Side-note : it is better practice to check for duplicate GCM registration id as well. because google refresh all GCM ids frequently.
Hope this will help.
EDIT
as #Haunter suggested,
what if the users have a multiple devices?
Well in this case use store IMEI number on your database and check for that instead of user id.
how to get IMEI number
TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = tel.getDeviceId().toString();
Some changes on my code: (Might help someone)
I have remove IMEI to avoid issues. In order for the server to validate all users registration id to be valid, even he/she reinstalls the app. When an android device registers it new registration id on the server. After saving the new registration id,server will run a worker, starts gathering all the registration id of the current user,then send a dummy notification (empty string) on each registration id, when gcm respond with a canonical Id > 0 or an error like NotRegistered, I then delete the registration id,

Google Cloud Messaging - Does Android client have to send registration token to my application server?

I am new to GCM and not clear about the registration process between client and the app server. Since GCM upstream messaging is available, when client registers with GCM, is it possible that GCM can send the registration data to app server, so the android client doesn't have to send the registration token/id to app server like the old day?
I saw a push notification diagram somewhere that shows no connection between app server and the client. All the communication can be passed through GCM.
Thanks!
is it possible that GCM can send the registration data to app server, so the android client doesn't have to send the registration token/id to app server like the old day?
if you intend to send messages to individual devices you still have to send the reg id to your server.
if you do not need to have the ability to send to individual devices then you can have the app subscribe to topics and then all your server has to do is send a message to a topic and anyone subscribed to that topic will get the message
The client has to inform the token to the app server somehow.
From the docs:
(...)
2 - The client app passes the registration token to the app server
3 - The app server saves the registration token and acknowledges to the client app that the process completed successfully
If you have seen the registration diagram then you may notice that your app connects with GCM server to obtain a key. So basically your app acquires a token ID. That means your app needs to send this id to your server and not GCM server.
Then you can simply send Push Notification to a Single user, Groups of User, or to an Topic.

Expiration tokens of gcm

I am implementing the GCM service on my app, but I have some doubts. When a user installs and opens my app for the first time, it gives him a token to receive notifications, this is saved in the database of my site. When the user decides to uninstall my app, I think the token is not useful anymore, so I was wondering if is possible to know the expired token and delete it from my database.
When your App Server sends a message to GCM Server, trying to reach a client on which your app has been unistalled, it (the GCM Server) should return a NotRegistered Error. So the app Server should remove the token from the database.
Usually (it actually depends on the client platform) when the app is unistalled, what happens is:
The end user uninstalls the client app.
The app server sends a message to GCM connection server.
The GCM connection server sends the message to the GCM client on the device.
The GCM client on the device receives the message and detects that the client app has been uninstalled; the detection details depend on
the platform on which the client app is running.
The GCM client on the device informs the GCM connection server that the client app was uninstalled.
The GCM connection server marks the registration token for deletion.
The app server sends a message to GCM.
The GCM returns a NotRegistered error message to the app server.
The app server should delete the registration token.
This means that if noone tries to send message to your client (the one who unistalled the app) you should never be able to understand if a token is still used.
If for you is important to remove all unused tokens, IMHO you can overcome this problem creating a test message that is triggered (for example once a month) from you App Server: this should conduct you to the point 2.

Android: Delete record from remote database on app uninstall

I have written an application (AirQApp) for general public as well as for our customers. When customers log in with the given username and password, it stores the device registration ID in the central database to generate gcm notifications for the specific customer similarly when they logout it deletes the device ID, but when they uninstall this application, it cannot delete the device ID from the database hence notifications are still generated.
I googled it and it seems like it is not possible to perform a task on application uninstall.
Is there any other solution which can be applicable in my scenario?
Is there any way to check if the application is installed on a particular device from device registration ID?
Thanks in advance.
The end user uninstalls the application.
The 3rd-party server sends a message to GCM server.
The GCM server sends the message to the device.
The GCM client receives the message and queries Package Manager about whether there are broadcast receivers configured to receive it,
which returns false.
The GCM client informs the GCM server that the application was uninstalled.
The GCM server marks the registration ID for deletion.
The 3rd-party server sends a message to GCM.
The GCM returns a NotRegistered error message to the 3rd-party server.
The 3rd-party deletes the registration ID.
From Here
I googled it and it seems like it is not possible to perform a task on application uninstall
Correct.
Is there any other solution which can be applicable in my scenario?
The next time you try to send a message to that GCM registration ID, GCM should tell you that it is no longer registered.

Is there an Android GCM equivalent to the iOS Push Notification Feedback Service?

Our webapp sends push notification requests to iOS and Android devices.
For iOS, the Apple Push Notification Service has a feedback service so you can detect which devices have uninstalled your app and then remove it from your database.
Is there a similar feedback service for Android GCM? If not, how to detect which Android users no longer have the app installed?
Is there a similar feedback service for Android GCM?
No.
If not, how to detect which Android users no longer have the app installed?
Quoting the documentation:
The end user uninstalls the application.
The 3rd-party server sends a message to GCM server.
The GCM server sends the message to the device.
The GCM client receives the message and queries Package Manager about whether there are broadcast receivers configured to receive it, which returns false.
The GCM client informs the GCM server that the application was uninstalled.
The GCM server marks the registration ID for deletion.
The 3rd-party server sends a message to GCM.
The GCM returns a NotRegistered error message to the 3rd-party server.
The 3rd-party deletes the registration ID.
Note that it might take a while for the registration ID be completely removed from GCM. Thus it is possible that messages sent during step 7 above gets a valid message ID as response, even though the message will not be delivered to the device. Eventually, the registration ID will be removed and the server will get a NotRegistered error, without any further action being required from the 3rd-party server (this scenario happens frequently while an application is being developed and tested).
GCM will respond you with the "NotRegistered" error (assuming you use HTTP).
Also, GCM has recently released for iOS, so you can use it to deliver both Android and iOS notifications.

Categories

Resources