how use firebase android for multiple id application - android

I have an application that is different for each user, id application is different for each user, so idApplication is dynamic. My problem is that json retrieved from firebase is linked to a single application id. How can I use one file json for all the applications I generate dynamically?
_______édit ____
I don't know thé application id, this application id is modified on a filé jenkins.properties on my project Android, and when jenkins générate New apk it do it with thé New id

Instead of relying on google-services.json and associated gradle plugin you can dynamically create FirebaseApp using something like following (I have this in dagger module)
FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
.setApiKey(apiKey)
.setApplicationId(someApplicationId)
.setDatabaseUrl(databaseUrl)
.setStorageBucket(storageBucket)
.build();
firebaseApp = FirebaseApp.initializeApp(context, firebaseOptions, "MyApp");

Related

Using FirebaseAnalytics from inside a library

I want to use FirebaseAnalytics inside a library project on android. I want the events logged to be reported to my Firebase console and not to the console of the app developer. I do not own or control the implementation of the app that will use the library.
Is this possible in any way?
My approach:
I have read this and found out that it is possible to create a FirebaseApp using my credentials as follows:
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("Your AppId") // Required for Analytics.
.setApiKey("You ApiKey") // Required for Auth.
.setDatabaseUrl("Your DB Url") // If you wanted to
.build();
FirebaseApp.initializeApp(context, options, "CompanyA");
Is there a way to use this FirebaseApp to log events as in FirebaseAnalytics?

"Could not reach Firestore backend", multiple Firebase apps, Android

I'm migrating from Realtime Database to Firestore. Because I can't have both a Realtime Database instance and a Firestore instance in the same project, I have to init the Firestore instance manually, rather than have it pick up the google-services.json file automatically as part of the build. I've done that like this:
FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
.setProjectId("***")
.setApiKey("***")
.setApplicationId("***")
.setDatabaseUrl("https://***.firebaseio.com")
.build();
FirebaseApp firebaseApp = FirebaseApp.initializeApp(this, firebaseOptions, "dev");
FirebaseFirestore db = FirebaseFirestore.getInstance(firebaseApp);
All the values are taken from the google-services.json file I downloaded for the new project.
Calling FirebaseFirestore.getInstance() is fine, but when I later try to get a document, I see this in logcat:
W/Firestore: (0.6.6-dev) [OnlineStateTracker]: Could not reach Firestore backend.
The Task for a get() call to a Document has an exception message of:
Failed to get document because the client is offline.
The device is online, for sure. The new project in the console does NOT have the SHA certificate fingerprints set, because I can't use the same one as for the original project.
What am I missing?
[Edit]
I know that is a little late for the answer. In my case, I had the same problem because I try to test Datastore and I lose the possibility to use Firestore in my project. When I try to create a new project for Firestore, I have to init the Firestore instance manually and I had the same problem.
In my case, the problem was that one of the parameters of FirebaseOptions was wrong (in my case was project_id because I had put project_number). I had taken all parameters from google_services.json from the new project:
FirebaseOptions.Builder()
.setApplicationId("X:XXXXXXXX:android:YYYYYYY") // FROM client_info -> mobilesdk_app_id.
.setApiKey("AIzaXXXXXXXXXXX") // FROM api_key -> current_key
.setDatabaseUrl("https://XXXXXXX.firebaseio.com") // FROM firebase_url.
.setProjectId("XXXXXXXX") //FROM project_id
.setStorageBucket("XXXXXXX.appspot.com") //FROM storage_bucket
.build();
After that everything start to work fine.

Multiple public Firebase Database Instances in Android

I'm working on an assignment. I've to use Database provided by a provider 'hacker-news'. Also i've to use Firebase Authentication. I've setup a new project in my own account. Retrieving data from Hacker-news database works with below line. I'm able to fetch publicly accessible data with firebase child() APIs is
database = FirebaseDatabase.getInstance("https://hacker-news.firebaseio.com/");
But when i implemented Firebase Authentication and once user logs in it is giving error
Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly. Make sure your google-services.json file has the correct firebase_url and api_key
I've spent lot of time on internet and found a link to implement multiple databases in single project -
Working with multiple Firebase projects in an Android app by Google
This works only if you are the owner of those Databases. Is there anyway i can access Hacker-news Database using SDK not REST-API?
FirebaseOptions options = new FirebaseOptions.Builder()
.setDatabaseUrl(getResources().getString(R.string.dbURL))
.setApiKey(getResources().getString(R.string.api))
.setApplicationId(getResources().getString(R.string.appID))
.setProjectId(getResources().getString(R.string.projectId))
.setStorageBucket(getResources().getString(R.string.storageBucket)).build();
//set all variable above as your need
boolean hasBeenInitialized=false;
List<FirebaseApp> fireBaseApps = FirebaseApp.getApps(getApplicationContext());
for(FirebaseApp app : fireBaseApps){
if(app.getName().equals("any_name")){
hasBeenInitialized=true;
}
}
if (!hasBeenInitialized) {
smaTeacher = FirebaseApp.initializeApp(this, options, "any_name");
}
database=FirebaseDatabase.getInstance(FirebaseApp.getInstance("any_name"));

Firebase initialization in case of Multiple sender id

I have multiple sender id in project. As per Firebase Document, below is the code for Firebase initialization:
FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId("ApplicationId")
.setApiKey("your_api_key")
.setDatabaseUrl("https://your-app.firebaseio.com")
.setStorageBucket("your-app.appspot.com");
FirebaseApp.initializeApp(this, builder.build());
Below is the reference:
Use multiple projects in your application
App is receiving push notification from multiple Firebase project/ multiple sender Id. Can I use default initialization (using google-services.json) or initialization would be done manually as per the mentioned code/link?

Can not add Apple client ID to Firebase invites intent on Android

When creating Firebase invite intent I try to add link to iOS app as described in documentation:
intent = new AppInviteInvitation.IntentBuilder(context.getString(R.string.invitation_title))
.setMessage(context.getString(R.string.invitation_message))
.setOtherPlatformsTargetApplication(
AppInviteInvitation.IntentBuilder.PlatformMode.PROJECT_PLATFORM_IOS,
"1059710961")
.build();
"1059710961" and "mobi.appintheair.wifi" both cause the same error:
AppInviteAgent: Create invitations failed due to error code: 3
AppInviteAgent: Target client ID must include non-empty and valid client ID: 1059710961. (APPINVITE_CLIENT_ID_ERROR)
What is the correct format for this parameter?
To get this client ID you have to do the following:
Register you iOS app in the Firebase Console
Download GoogleServices-Info.plist for iOS app as we download google-services.json for Android
Look in it and found value for the key CLIENT_ID (will be something like this 123456789012-abababababababababababababababab.apps.googleusercontent.com)
Add it to builder:
intent = new AppInviteInvitation.IntentBuilder(context.getString(R.string.invitation_title))
............
.setOtherPlatformsTargetApplication(
AppInviteInvitation.IntentBuilder.PlatformMode.PROJECT_PLATFORM_IOS,
"123456789012-abababababababababababababababab.apps.googleusercontent.com")
.build();
the client_id is the one in the plist you download from the firebase console for your iOS app

Categories

Resources