I have published an android app that uses Firestore for the database. Now, I want to enable push notifications.
I have figured out I need to attache a device token id for each user to send notification to a specific device. The problem is that I have lots of old users! Is there anyway to add token id for each one instead of waiting for all users to upgrade the app?
The only way you can collect device tokens is from the device itself. So, your users will have to upgrade their app to version that collects the tokens, associates it with the user, and writes it to Firestore.
Related
I am using Google's Firebase to manage some of the back end aspects of my mobile application.
Mainly I am using it for authentication with email as well as sending push notifications.
Currently, I have around 10 users who have been registered for a push notification token.
My question is that, I want to send a notification to only 8 users. Is this possible, because I can't seem to find a location where I can select the users.
I tried disabling the users from the Authentication tab but that seems not to make it work as authenticated users and Push-registered users seem to be different.
You can target FCM messages:
To the iOS or Android app that is being used (through the Console only).
To an Analytics audience that the user of the app is part of (through the Console only).
To a topic the app instance is subscribed to (through the Console and the API).
To a group of devices, if you know their group ID (through the Console and the API).
To a specific device instance (i.e. a specific app on a specific phone) if you know their instance ID token (through the Console and the API).
There is no way in the Firebase console to select the users to send a message to. In fact: Firebase Cloud Messaging has no concept of a user, all it knows is the token that identifies the app that it's part of on the device that it's installed on.
I'm migrating to Firebase Cloud Messaging, and I have one doubt.
My application must show the login screen when launching, and if the user performs login in another account, I must stop send notifications for the older user.
What's the best way to do that?
Can I force the application to renew the token?
Or should I update the token's owner in my base by my own?
Inside application You should renew Instance ID token and forget about the old one if You don't want to get notifications being sent to the old token. On every logout and login just take new Instance ID and update Your external database (in case Your application logic need it) with information about new token being assigned to that user :) There are no limits for generating new tokens and You cannot reuse once dropped tokens.
Renewing token is just calling getToken() again.
This is the best approach because InstanceID is in fact assigned to the "application instance" so in case of app reinstall on device or removing cache by user You'll have to get new token anyway.
In one of the apps I developed, I handled it on my app cloud.
Cloud had two tables, a table with device ids a user is logged in with and another with instance ids assigned to devices.
What you can do is, as user logs out from a device, remove that device id from users device list and as a new user log in you add a device id to his devices.
When sending notifications you can devices with tokens and everything else will streamlined
I want to store FCM token in my android app user's table in database when user register to the app . When i want to send notification to specific user then i will fetch Token from corresponding row and send push notification.But i am confused that whenever app user logout from his app and register new account from same device ,then there will be two row and hence two Token for same device on database. How to handle such case? What happen to old Token in device? please anyone can help me??
The Instance ID token used to send FCM messages represents the instance of and app on a device. The current user of the app would not affect the token that represents the app instance. Uninstalling and reinstalling the app would cause a new token to be generated but not for in app behaviour like switching users.
You should still remove the mapping of the token to the user on logout and add a new mapping with the same token to the user that logs in but it will be the same token.
I probably feel this may help you,
When user logs out clear his device token and make him Logout so that he won't be able to receive the updates and hence only one user at a time can get the updates
I have a android client app, a server side in django and now I am adding push notifications with GCM.
In my app I have users that login/logout, so I will have a table in my database with devices ids coupled with users, so that every time I want to notification a user, I will lookup its device id and send the notification.
my question is:
When is best to register the Device to the GCM?
When to add the Device to my Server side database?
In the Google Docs it says you should do it once, when the app is installed.
Because I have users in my app, and I want to couple a user with a device in the database, when the app is installed there still isn't a user to associate the Device with.
After the user installs the app, he can register, login and so on.
So when you think is best to register the Device to the GCM and to my server side?
Should it be with a user or only associate it later?
Thanks a lot!
My suggestion would be:
Register the device immediately after the first execution
Save device id somewhere accessible anytime by the app
Couple the id with user details after registration
With this approach you will be able to handle issues if something goes wrong with the registration process and send a notification to the device even if the user is not registered.
EDIT:
You should also implement a strategy to check on a regular basis if the association between the user and the device is still valid or needs to be updated
I am using parse as my app back-end service provider. My app has really important feature of Push notification.
Parse is not saving the device token in some cases. Mostly when user is installing the app from America/Los_Angeles region.
Is this Parse.com sdk integration problem or Google is not sending device token in some region? How can i fix this issue?
I've just ran a quick check on our Parse backend and found that there are also missing device tokens in our database, too.
I think you should not send push notifications based on device token, but based on user on that device.
To do that, first add a new field in Installations table called user. If your app requires explicit login from user, then when user logs in, update the installation with that user's ID. If it is implicit (registers upon installation so App is ready to go as soon as user opens the app), then just associate that user in the same manner on app install.
In the end, you are most likely to want to send your notifications to your user rather than a specific device. This also makes data transferring a lot easier.
This issue was sometimes observed due to failure to get the token from Google. You should check the device token availability, if you don't get it, you should try it again after some time from your app.