I have developed an Android APP based on Firestore for DB storing data.
Now I need that the user is able to configure on the APP at run-time the end-point of Firestore DB - these parameters are typically stored in google-services.json (firebase_url, project_id, storage_bucket)
How can these values be changed at run time? Is there a specific Android API to do this?
Thanks in advance for any suggestion/support on this matter :)
You will have to take control of the initialization of your app, rather than allow the default initialization. This is kind of complicated, and it involves calling FirebaseApp.initializeApp() correctly with the details of the project you're trying to access.
I've written a couple blogs about this:
https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html
https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html
Related
So I have the following situation where It's hard to make a specific question besause I don't really know very well what my options are:
I have an Android App where I have "servers" to represent subjects, I want to change these subjects from time to time (I intend to use remote config for that) but I also need some kind of trigger so every time I change a subject the correspondent server get "cleaned". The better way I can think of is that I need to change the values directly on database. So tha question is... How to access and change values on db from a change on remote config? I accept any other suggestion
Changes in Remote Config are limited to just that product. There is no simple configuration to have those changes reach out to other products.
What you can do instead is use a Cloud Functions Remote Config trigger to have run some backend code that you write to make changes to the database. A full set of instructions to do this is outside the scope of a Stack Overflow answer, so I suggest you start with the documentation for Cloud Functions to understand what it does and how to get started writing triggers for Remote Config changes.
I want the "backup" part to be done in the background and would only start if the user is not using it. I am using android-priority-jobqueue and have made a Job object that would achieve this.
Here are my current problems :
But now I am thinking of how I can make sure that the user is not using the app so that I can run the job. I am also thinking how I can backup or sync the database while the user is using the app like in multiple other apps.
I don't know how I can restore the data back to the app without missing any data. Like for instance, there are two devices. Device 1 backed-up its database into Google Drive. Now, Device 2, being that it had no connection for a few hours, it created new entries into the database. Then it connected to internet and it has to get the other entries from the Google Drive without overwriting the entries it currently has.
I really am confused about when to sync, when to backup, and how they can be flawlessly achieved.
Can anybody please help me
For #2, if you are using GDAA to upload the file, you can pass an ExecutionOptions that allows you to handle conflicts. This lets you implement any arbitrary logic to resolve the upload conflict, e.g. maybe in your case it's to merge contents from both devices. However, note that currently conflict detection is only possible for updating an existing file, not for creating a new one.
For more reference:
https://developers.google.com/drive/android/completion#conflict
https://developers.google.com/android/reference/com/google/android/gms/drive/ExecutionOptions.Builder.html#setConflictStrategy(int)
Sample code for conflict resolution:
https://github.com/googledrive/android-conflict
I am trying to learn Google Cloud Storage with JAVA for some days and i was inserting some data in datastore and the inserted data's could be seen from here //localhost:8080/_ah/admin/ . Now when i stopped this session and again run the backend some weird behavior i saw.
Case 1: When i am running it again my previous data's are gone.
Case 2: If i have inserted 4 data's in the datastore in a session and then in the next session 2 or 3 of my previous data are missing.Here in this case not all the data. And also sometimes one data is missing.
I searched for this and i saw that the local_db.bin will be created in every run. I prevented it by adding the following condition in VM arguments - Ddatastore.backing_store=PATH.
But still i am having inconsistent behavior. Though the local_db.bin file is not being deleted, but the datastore behavior is erratic. (For example sometimes the entities are successfully preserved, and sometimes some of the entities are deleted).Will this happen when i integrate with my android app?
During startup, the App Engine dev server displays the location of the datastore file it is using. I have seen in the past where a different datastore file is used when starting the server each time.
You can copy the datastore file to a location of your choice. Use the datastore_path flag to inform the dev server which data file to use. This will allow the dev server to use the same datastore file each startup.
dev_appserver.py --datastore_path=/data_path/myapp_datastore myapp
You should not see random data disappear from your app as you have mentioned. One thing to keep in mind is that the Google Cloud Datastore uses an eventual consistency model. So, if you are inserting a new record in the same process as returning a list of all records - you may not see that new record until you refresh the page in your app.
There are ways to force strong consistency by using ancestor queries. More on ancestor queries can be found in the documentation:
https://cloud.google.com/appengine/docs/python/datastore/queries#Python_Ancestor_queries
In cause you're developing in Java, you've to provide VM arguments like this
-Ddatastore.backing_store="/path/to/datastore/file/location/local_db.bin"
More here: https://code.google.com/p/android/issues/detail?id=68225
You can also find another solution for custom datastore location using Java dev server in my question.
//localhost:8080/_ah/admin/ shows only data that is used locally on your computer for testing purposes only. It is not linked to the actual Datastore in any way. You should also test your app with actual data after you deploy your app to the App Engine.
I'm about to build a GPS Spot Finder application with Android and I am trying to decide what requirements are feasible and what aren't. The app would enable users to essentially add different spots on a Google Map. One of the problems would be fetching the data, adding new spots, etc, etc. This, of course would mean the database would have to be online and it would have to be central. My question is, what kind technologies would I need to make this happen? I am mostly familiar with XAMPP, PHPMyAdmin and the like. Can I just use that and connect Android to the database? I assume I would not need to create a website...just the database?
What different approaches can I take with this? Be great if people can point me in the right direction.
Sorry if I don't make any sense and if this type of question is inappropriate for Stackoverflow :S
Create a website to access the database locally, and have Android send requests to the website.
If users are adding spots to a map that only they see, then it makes sense to keep the data local to Android using a built-in database (SQLite). That looks like
ANDROID -> DATABASE
You can read up about SQLite options here.
If users need to see all the spots added by all other users, or even a subset of spots added by users, then you need a web service to handle queries to the database: Connect to a remote database...online database
ANDROID -> HTTP -> APPLICATION SERVER -> DATABASE
Not only is trying to interface directly to a database less stable, but it may pose risks in terms of security and accessibility.
Never never use a database driver across an Internet connection, for any database, for any platform, for any client, anywhere. That goes double for mobile. Database drivers are designed for LAN operations and are not designed for flaky/intermittent connections or high latency.
Additionally, Android does not come with built in clients to access databases such as MySQL. So while it may seem like more work to run a web service somewhere, you will actually be way better off than trying to do things directly with a database. Here is a tutorial showing how to interface these two.
There is a hidden benefit to using html routes. You will need a programming mindset to think through what type of data is being sent in the POST and what is being retrieved in the GET. This alone will improve your application architecture and results.
Why not try using something that is already built into android like SQLite? Save the coordinates of these "spots" into a database through there. This way, everything is local, and should be speedy. Unless, one of your features is to share spots with other users? You can still send these "spots" through different methods other than having a central database.
And yes, you just need an open database, not a website, exactly. You could technically host a database from your home computer, but I do not suggest it.
If you are looking at storing the data in your users mobile nothing better than built in SQLLite.
If you are looking at centralized database to store information, Parse.com is a easy and better way to store your user application data in centralized repository.
Parse.com is not exactly a SQL based database, However you can create table , insert / update and retrieve rows from android.
Best part is it is free upto 1GB. They claim 400,000 apps are built on Parse.com. I have used few of my application typically for user management worked great for me.
I'm developing an Android app as a "proof of concept" for our company. If they like it and think it's worth investing, then we'll move on to bigger things. I'm trying to figure out the best/most practical approach for this.....the basics of the app will connect to our DB and display information regarding a specific customer. For now, let's say we will only pull data from 3-4 tables (but there could be 10+ in the future). If the app doesn't have an internet connection then it should use the local DB. What is the best approach for this? Here's what I was thinking and would like some input/suggestions if possible:
1.) app runs checks internet connection. If exists, check db version (how, through a web service?)..if server db is newer, get latest data. If no internet, use local db.
2.) app parses data and displays it.
If this is correct, then there could be no modifications to the web service that would add fields to a result without changing the app as well. Is there a way for an app to parse fields regardless of how many fields there are?
I've read and walked through the tutorial on google with databases and such (Notepad tutorial) but it seems like the column names are all hard-coded in the parsing class, which I was hoping to avoid.
Sorry if this is confusing but I know I need my app to use a local db to read data, I also know that the app must get data from the server when it can (via onCreate or a refresh button) and copy it locally....Copying it locally is the part I'm having trouble understanding I guess....is there no way of saying "go out and get this result and display it", knowing that those results could mean 5 fields the first time or 1 the next.
Any help/guidance is greatly appreciated!
You probably want to use a SQLLite DB to store your data locally, a ContentProvider to provide CRUD access to the db, and a SyncAdapter to sync with your server when possible. The Sync Adapter also writes to the DB via the ContentProvider. See the SampleSyncAdapter sample in the SDK for an example of how this works. You will be implementing your own ContentProvider, but the sample just uses Android's supplied Contacts ContentProvider.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html