Android Question FCM - how to make Firbase data configurable at run-time?

amorosik

Expert
Licensed User
Following Erel's tutorial on Fcm, one of the steps to follow is the use of the json file as downloaded from the Firebase website to be included in the app project files and which will be used during the app compilation, making the union uneditable between app code and Firebase configuration data
This prevents you from changing the parameters and using the app with another Firebase account
The question is: how to make the data for connecting to Firebase Cloud Messaging, to receive push notifications, configurable at run-time?
 

amorosik

Expert
Licensed User
What is the use case for sending messages from a different account? I don't think that it is possible.

The classic example is when you are developing an app that requires receiving push notifications
When you are developing you will use your Firebase account
When you pass the app to the buyer, you will need to use their account
If this setting were read by the app at the time of startup, it would avoid creating two different apps, one's own for testing, and that of the customer with his account
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
How about using robocopy to copy over different google-services.json depending on the build configuration.

example,
B4X:
#if dev
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\devjson" "..\Files" google-services.json
#else if storerelease or test
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\testjson" "..\Files" google-services.json
#end if

it is safe to add the same app to multiple firebase projects. This is not quite runtime, but at least it is automated on build.
 
Upvote 1

amorosik

Expert
Licensed User
How about using robocopy to copy over different google-services.json depending on the build configuration.

example,
B4X:
#if dev
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\devjson" "..\Files" google-services.json
#else if storerelease or test
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\testjson" "..\Files" google-services.json
#end if

it is safe to add the same app to multiple firebase projects. This is not quite runtime, but at least it is automated on build.

Yes, many thanks, this solves my problem, development version and production version
But in the more general case where the same app is released to different customers and it is necessary to configure the app with your Firebase account?
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
In this case I would have 1 firebase account and use different topics for each customer.

So at startup a TOPIC_PREFIX is read.

in the send notification code the TOPIC_PREFIX is added to the TOPIC NAME.

Each client app listens to their own item with TOPIC_PREFIX+topic.

Example

Client1 - TopicPrefix - "C1"
Client2 - TopicPrefix - "C2"

Topic is "SENDMSG"

Client1 listens to "C1SENDMSG"
Client2 listens to "C2SENDMSG"

No conflict.
 
Upvote 0

amorosik

Expert
Licensed User
In this case I would have 1 firebase account and use different topics for each customer.

So at startup a TOPIC_PREFIX is read.

in the send notification code the TOPIC_PREFIX is added to the TOPIC NAME.

Each client app listens to their own item with TOPIC_PREFIX+topic.

Example

Client1 - TopicPrefix - "C1"
Client2 - TopicPrefix - "C2"

Topic is "SENDMSG"

Client1 listens to "C1SENDMSG"
Client2 listens to "C2SENDMSG"

No conflict.

Of course, the topic is a variable that you can change at run-time
I'm talking about using a different Firebase account at run-time
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
My understanding of the overarching problem is that you want to ensure that different instances of a base app use different firebase databases, but maybe I misunderstood.

Given that to create a different instance, you need to recompile the app to give it an app id, then the first solution proposed will work.

If all your apps have the same app id, then the second solution will work.

Trying to access multiple firebase accounts in the same app is discussed here:


However, if you read through the solutions, you will see that the API used to make them work is deprecated.
 
Upvote 0
Top