I have an app that sync data with my API.
I want this app have a dynamic "google-service.json", I want to pass the google-service.json after the app.APK is ready and the app is installed on the device through my API.
Is possible ?
I did a generic "google-service.json" that change the values when I send data from my API to the installed app on the device but the Firebase connection is not working.
Any ideas ?
What you're asking isn't possible. The values from google-services.json are read at build time and added to your APK. There's no way to go back and changes those values later.
If you want to initialize Firebase based on values that can only be known when the app is launched, then you should NOT apply the google-sevices plugin in build.gradle, and instead call FirebaseApp.initializeApp() manually and pass the correct values that you see in google-services.json.
Read:
https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html
https://developers.google.com/android/guides/google-services-plugin
Related
How can I set the sender id when requesting a registration token for Firebase messaging in Android?
I need this, because I have to have different FB projects for the apps and the server that is sending the notifications. It's described here, but I think the doc is missing something. Searching StackOverflow results in answers that are not up-to-date, also. Can't find the way to do it with the latest version of the API.
I suggest having a read on controlling your Firebase registration/instance it also explains not only how to manually initialise your own firebase with custom options/name but also how firebase initialises itself automatically using the Google plugin and json file which will help you better understand what solution may be best for you.
Essentially you need to manually initialise your Firebase service in your Android apps Application class and provide a FirebaseOptions.Builder class to the Firebase.initializeApp, which allows you to call setGcmSenderId among other things like api key etc.
This official link shows how to configure mutliple projects in your application which may be an option too.
I wanted to keep using the google-services.json, so I didn't want to do the manual init. Then when I read how the Google Services Gradle Plugin works, I was going to make the manual init by using the values from the file - more info here: https://developers.google.com/android/guides/google-services-plugin#processing_the_json_file
In the end, I ended up not changing anything in the code and just changing project_info/project_number in the google-services.json. It's used for gcm_defaultSenderId. Everything looks good, now. Hope it's not used for anything, else. We are using FCM, only, so I think it will be ok. I don't like this, but it will do.
the sender id and project details are set using configuration file "google-services.json",it reads this file from app folder of your android project.
to get google-services.json for your firebase project in firebase console, open project settings and select your app and download the file and place it inside app folder of your android project.
I have an Android App where I want to the UserName and serverURL to be pre-filled when device opens , Based on the device enrolment it will fetch the these values on userName and serverURL field .
Can I use Android Restriction API to get those configuration value.
like below
List<RestrictionEntry> restrictions =
manager.getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
It seems documents kind of vogue for Android
Android documentation isn't perfect but at least this one about managed configurations is a bit good ;) .
To provide externally managed configurations:
Declare the managed configurations in your app manifest. Doing so allows the IT admin to read the app's configurations through Google Play APIs.
Whenever the app resumes, use the RestrictionsManager object to check the current managed configurations, and change your app's UI and behavior to conform with those configurations.
Listen for the ACTION_APPLICATION_RESTRICTIONS_CHANGED intent. When you receive this broadcast, check the RestrictionsManager to see what the current managed configurations are, and make any necessary changes to your app's behavior.
You can also check the sample projet AppRestrictions for more details.
Good luck
I've been working on an app which displays a list of websites when click on it will be redirected to webview in the app itself, I'm unable to find a way how to update the links dynamically without updating the app. So, If I want users to interact with new links the new links should automatically be updated in the app without update and in the webview too. Is it possible to do that?
You should use firebase remote config feature, which best fits in your case.
Firebase Remote Config is a cloud service that lets you change the
behavior and appearance of your app without requiring users to
download an app update.
Well to do that you first need to create a project in firebase console
In remote config feature you can add data in key-value pair. Like in this image:
I have added two key-value pair, as can add as much as you want. Now in the app side you have to add dependency:
implementation ‘com.google.firebase:firebase-config:11.8.0’
And to fetch the values which you have added in firebase, you can easily get those url but first you need to follow some steps to do that. You can check this simple tutorial.
Note: To get the values from firebase remote config you must need to click on publish changes button(Which you can see in above image top right corner).
You can store that link to a server and return that link when the app hits a certain API of that server. But for doing that, you need to setup a server, build a server application if you haven't already. Which is a lot of work for just storing a website link.
Another option could be, you can use services like http://bit . ly and create a custom link from that service, like http://bit . ly/my_specific_domain and use this link in your app. When you need to point to a different website, you can just update where http://bit . ly/my_specific_domain redirects to.
But you best bet would be to use Firebase Remote Config, which is both reliable and easy to implement, but that is already described in previous answer.
I have a question regarding the Firebase google-services.json file. Every time I add o change something, for example, if I add a new SHA1 fingerprint, do I need to download the file again and put it on the app folder of my Android project? or just the file created the first time is enough?
I am asking because I am having issues with the Phone authentication and I need to know if the problem lies on this matter.
Yes, every time you add a fingerprint (or new package name) you will need to pull down the google-services.json.
I am currently writing an app (App A) that depends on another app's data (App B).
Being an Android noobie, I thought that the only way to enable that is to use a ContentProvider and doing a query.
As it stands, the current way of doing is problematic, because App B has another signature than the one we're using for App A. This means:
The only way we can get our apps to talk to each other is to send our apk on a signing server so that it is also signed with the same key used for App B
This process is not automated, so it is therefore time-inefficient (takes around 2 - 4 mins).
This also mean we can't set debug points, which causes us a lot of pain when trying to see what data exactly is being returned by the ContentProvider
I did some more research and got told by a colleague that instead of signing our apk every time we make a slight change, we could extract the apk of App B and sign it with our key only once.
It led me to then create a keystore and key for my team, which I used to re-sign App B's apk and reinstall it on our test device. I then set my Android Studio to automatically sign the debug versions of App A with that exact same key.
The problem is that didn't change anything unfortunately...
It always ends up with the following exception being thrown:
Failed to find provider info for com.App.B.provider
(basically the same error thrown when we are using the default App B apk withouth sending our App A apk to the signing server)
Just to point out, if you're wondering, sending App A's apk to the signing server and running that does work and we're getting the data from the ContentProvider
So yea, I'm not sure what to do anymore... Any ideas ?
Also, since I'm not sure I have a clue of what I'm doing, any explanation of how these things are supposed to go would be very welcome !
<provider> tag should be placed inside <application> tag.
Also, be careful not to put it inside an <activity> tag.
Also you can get it working specify full path in <authorities> tag in manifest file (see SearchableDictionary sample code in SDK).
<provider android:name=".DictionaryProvider"
android:authorities="com.example.android.searchabledict.DictionaryProvider">
Alternatively you can use external storage,create directories and access the data from there directly.