Melih Colpan
Melih Colpan

Reputation: 157

How can I edit google-service.json where in root folder from app?

I want to create a Firebase Cloud Messaging client. I want to get id, project id, package name and etc. from user and edit my google-service.json file. From textviews users can change informations and can use with their projects informations. Is there any way to do this?

Thanks for your replies!

Upvotes: 3

Views: 634

Answers (2)

Arthur Thompson
Arthur Thompson

Reputation: 9225

An application can be registered to receive messages from multiple projects. By default the project defined in the google-services.json file will be used however you can request another Instance ID token using the getToken method and manually specifying another Sender ID.

So if the user defines another sender id you can then call getToken and messages sent to both the initially generated token and the one you generated manually will be received by the app.

Upvotes: 0

Bob Snyder
Bob Snyder

Reputation: 38309

Your desire to create a user configurable client is unusual. You must have some very special requirements. I don't think the type of FCM client configuration you want to do is possible. I'll explain my reasoning.

First, the google-services.json file is processed at build time, not run time. It is parsed by the Google Services Gradle Plugin, which generates an XML file of string resources at .../app/build/generated/res/google-services/{buildType}/values/values.xml.

When an app that uses Firebase starts up, the FirebaseInitProvider configures itself using those string resources, and creates the default instance of FirebaseApp. The default FirebaseApp is used by FirebaseMessaging.getInstance().

Some Firebase APIs, FirebaseDatabase and FirebaseStorage are two examples, provide getInstance() methods that accept a FirebaseApp parameter. For these, one can create a custom FirebaseApp using initializeApp() and FirebaseOptions.Builder to specify the values that are normally provided by google-services.json. But FirebaseMessaging does not have a getInstance() that accepts a FirebaseAppparameter, forcing use of the default FirebaseApp created using the google-services.json file.

Upvotes: 1

Related Questions