I have a Firebase project in which I registered multiple apps.
now I want to add push notification, and I want to be able to distinguish which app should wake up by the push notification.
in the google-services.json file, I see that all the apps have the same value for the current key in api key section, I understand it is because I registered the apps in the same Firebase project.
I also read about the SERVER_KEY, and saw that there is an option to add SERVER KEY. can I add multiple server keys and use them in my server, in order to send the push notification for the correct app?
or is there any other solution that allows me to keep the apps registered in the same Firebase project but distinguish which app should wake up by the push notification?
Yes, You can use multiple apps within the same project, you can use the firebase data structure to distinguish between apps:
(Use it as using channels)
https://www.firebase.com/docs/web/guide/structuring-data.html
With that said, from my experience, this is not recommended. At iOS platform, when multiple apps on the same device shared the same firebase keys, it caused some strange behavior for me, so my advice would be to open a new project per app (Pretty sure that is the documentary best practice too) Android worked fine.
Related
I have a Firebase Project with multiple apps(some iOS, some Android) within it. I'm using Firebase's Cloud Messaging along with the Node.js Firebase Admin SDK to send push notifications to these apps.
To authenticate, I'll set up a service account and generate a keypair for it, and use https://firebase.google.com/docs/reference/admin/node/admin.credential to do the authentication step.
Will this method work for multiple apps? Or will I need to create multiple service accounts and or keys? Also, if I have multiple Node.js API instances, can they all authenticate off the same service account/key simultaneously?
You only need one service account configured per project. It doesn't matter how many apps you have added to that project - you will be able to send messages to any of the devices where any of those apps are installed.
It's up to you to collect the device tokens and make sure you are targeting the correct devices with each push. You might need to create some way to discern which tokens came from which apps, if that matters for your push.
My setup consists of two android apps, that use the same backend. I was sending push notifications based on the deviceID, meaning if you installed both apps on the same device, the listener of app 1 would listen also to notifications intended for app 2, and hell would break loose.
I would like to know if Firebase can support this type of project.
So, does one Firebase project generates one Token per device per app, or only one Token per device?
If the latest, any tips on how to get this working?
Thanks in advance.
A registration (FCM) token corresponds to an app instance. AFAIK, different apps (unique by package name) should produce different tokens when getToken() is called regardless if it's using the same Firebase Project.
However, the usual (best?) practice is to have a separate project for every different app, then handle the multiple senders for each app.
I have created one project in my Firebase Account. In this project, I have added two android apps.
Now, while sending push notification through Firebase console, I see the option of selecting my individual app as shown below
But, while sending notification through Postman, I don't know how can I send notification to only a particular app?
Should I create two individual project for both my apps, so that the server key is different?
But, I feel there should be a way to send notification without creating multiple projects for multiple apps.
Sending notifications to user segments is not available programatically i.e. not available when using the API.
A workaround you could use is Topics Messaging, creating a topic for the specific app and subscribe the corresponding users.
I am working on an android app where I want to be able to use the notification system within Firebase. I want to use the advanced features where I can add key/value pairs so that I can implement the notifications to do different things under certain conditions when clicked.
I obviously only want to test this on my test/development devices but can't see a way to do this.
You should choose single device choice on "send notification" screen.
After that you should get your FCM registration token. Yo can get token via this app.
https://play.google.com/store/apps/details?id=com.tune.mytunedevice
Write your token and send notification.
You could create a new product flavor for your app (e.g. "development") (Configure Build Variants) and create a seperate firebase project (with a seperate google-services.json file) (Add multiple google-services.json files).
Then you have different API keys for each project which don't effect each other.
You can get the FCM registration ID for those testing devices and send the message just for them, or create a topic/testing and register those devices to that topic then send the message just for this topic.
Anyone have experience with it? I'm investigating migrating, but as we already have the app released with GCM, with thousands of users and thousands of notifications daily, I'm reluctant for fear of disrupting existing service. Did anyone manage a smooth transition?
Specifically, in the tutorial (https://developers.google.com/cloud-messaging/android/android-migrate-fcm) step one is 'Import Google Project'. Is this a one-way operation? Will existing GCM server solution and deployed GCM apps continue to work?
Or is the best bet to create a new project, and maintain two server solutions until the GCM deployed apps are phased out?
Importing your Google project into Firebase is a one way operation, however this is not a destructive operation, your current project will have required APIs turned on and necessary API keys will be generated for use with Firebase, but you can still manage that project from the Google Developer console if you decide not to continue using Firebase.
Your present server solutions will continue to work as before. I would go with importing your project to Firebase. It will be much easier than having to migrate your backend to a new project.
note:
If you were using pre InstanceID tokens for device IDs then they will not work in the Firebase console or with topics. So you would have to maintain a mapping of which users you can send to using the Firebase console and/or topics. If your were using GCM with InstanceID then there is nothing to do since FCM also uses InstanceID. You can use the FCM REST API to send to ALL tokens, InstanceID or pre InstanceID.
Be sure not to use GCM and FCM libs in the same client app. You can find issues when generating tokens and handling received messages.
First test out, There are many things to take care in FCM.
Major issues :
White Notification Icon while app is in background or killed.
App hangs after opening closing multiple times.
Read these issues to decide:
Firebase push notifications update DB
https://stackoverflow.com/a/37626817/1507602
How to handle notification when app in background in Firebase
After Upgrading to Google Play Services 9.0.0, App Hangs in DynamiteModulesC
Notification Icon with the new Firebase Cloud Messaging system