Synchronizing Firebase Storage Bucket CSV with Raw Files Android Java - java

I am looking for guidance in a proper way to use Firebase's Storage in order to synchronize some CSV files copies of which are stored in raw on the local device. I'm fairly new to Firebase storage.
Essentially, I wish to be able to push any changes made to the Firebase Bucket onto the local device. So anytime a CSV file is updated, a new one is added, or one is removed, I wish that to be synchronized with the copies stored on the device. Using the realtime database to store these CSV files in JSON is not an option for various reasons. It might also be worth mentioning that any file changes will be made by hand on the Firebase terminal.
I'm aware that Firebase allows us to list all the files contained at a reference point by calling .listAll() on a storage reference. However, I cannot find any documentation on this function or how to detect and update file changes.
Any help you can give me would be appreciated.

Cloud Storage for Firebase does not offer any APIs for automatically synchronizing objects in storage buckets between the client and server. It doesn't work at all like Realtime Database.
If you want to implement this, you will need to write a lot of code to implement that synchronization on your own. It won't be easy. You can take advantage of the sync provided by Realtime Database to reference which content might be new (if you store dates and paths to Storage), but ultimately, you will have to download and delete files manually as needed to make sure the client is up to date.

Related

Way to store images, text notes and audio files in offline database. Android, Java

I would like to create an app where I could save text, image and audio notes to an offline database(without internet connection) and then show them in a list-like layout. Wouldnt like to save the files to internal storage directly.
Its my first time creating mobile app so I need help in choosing the right database for such use case. Any suggestions?
I think you may be confusing some terms.
While you can put all sorts of media in a database. Sometimes it not the most practical solution. It sounds like you might be thinking of file storage, not a database.
Further more, the files have to live somewhere, if not on a external server/database, than they will have to reside locally on the device. Your app will not have a local database service running just so that it can store media files. This would be a lot of overhead and take up a lot of resources.
the first thing to know: the database in android is SQLite, So any other offline database it's just a layer for managing the SQLite database, and It only saves numeric and text data, but you can save any other type like image, audio, array...Ect by creating convertors to save it in the database.
E.g: You can save BitMap-Image type- by converting it to ByteArray-List of 0s and 1s-, then converting the ByteArray to String-Default text type-, then you can save it to the database, and when you want to select the value, just convert by the opposite (String -> ByteArray -> BitMap), So the trick here is to know how to convert between the types.
Now the answer:
the best offline-database is RoomDatabase, the fastest way to create and manage SQLite database, with Room you don't need to build an SQLite database from the scratch, it's going to build it for you, and has a great way to create converters.
but for you as a beginner, standard SQLite is more than enough, if you will see RoomDB more difficult.

How to get last created file in a bucket using Google Cloud Storage Java SDK?

How do I get the last created file in a GCS bucket using Google Cloud Storage Java SDK?
Currently, I am using the storage.list() and iterating through all the files and thus getting the last created file.
Is there a better way of doing this?
Cloud Storage doesn't offer flexible querying of objects. If you want to find objects based on some property, such as upload time, you should store that information in a database whenever an object created, updated, or delete. Then, you can just query the database to find what you want.
You could write a cloud function which copies any uploaded file to a fixed key (listen on the finalize GCS event), say key 1. Then your application just queries key 1.
Instead of copying the file you could also look at a peristent cache like Redis to store key 1.

Where to place my android app's data

I'm currently developing an app that lets you create and save excercises and routines for the gym. I want the app to come with some example excercises and routines and also to give the user the ability to add his own.
The thing is, I know I can use "getFilesDir()" and save it in the internal memory, but if I do that, how do I put my example files also in the internal memory? I don't think I can do that without creating those files by code everytime the app runs. I've also tried putting the example excercises in "res/raw" but then the ones the user adds go to a different place and I don`t know if that's good practice, apart from just how annoying it is having to read them from different places.
Where would be the best place to put those excercises and routines files?
Thank you very much!
The best practice is to store data inside "Sqlite Database".
"Sqlite Database" is the internal database that android provides to store data locally and is easy to use.
It's queries are easy to implement. It is more easy to work on, if you have worked on any database before. Just create a "Database Helper" class and initiate inside the activity where you plan to store data.
Many big applications like "whatsapp", use this database to store data on user's device.
The plus point of using "Sqlite" is that, you can iterate through each and every data easily.
It is quick, easy to work and is also a good programming practice. It is also secure.
While using a sqlite database for managing your app data is the traditional
approach, there are also alternatives to it. Realm is such an alternative. You can check the comparison with sqlite and see if it meets your need.
https://realm.io/
In Android development, you can store locally and as well as remotely. This link will walk you through all possible ways to store data.
As per your requirement, I would recommend you got for SQLite Database provided especially for android as it is light weight. Sqlite queries are straightforward and easy to use with some APIs comes with the package. you can start with this link with Sqlite.
I suggest using Firebase to store your data. Not only it is online and realtime, it can also work in offline mode and sync later. Because you're developing a gym app, why not give it an online or offline capability? I think users prefer it that way. You can check it at firebase.google.com

How to save files on android storage, write to them, and access them later on?

I am working on an android app to take float values from 3 different arrays, transform them into strings and then store them into a text file on the internal storage of the phone. I want to be able to access these values later and put them on a computer so I can do some statistical analysis on them. Can someone please show me how to do this?
Create a File object, and store your values in a flat-file database. For more info on how to create a flat-file database, go here. To learn more about the File API, go here. To learn about more data storage options that Android provides, go here.

SQLite on Google App Engine

Is it possible to use SQLite as a relational database from Google App Engine? (Java) I need read/write access to it from the app itself.
Also, I am using Quercus for PHP, and if what I am asking for is possible, I can handle storing the database myself.
No, it is not possible. This would require write access to the filesystem, which App Engine does not allow.
SQL database support (MySQL like) is planned, but no release data has been given. For now, use the datastore.
I know it's a super old question and nothing concerning read-only properties of App Engine has changed since then... But actually you can use sqlite on Google App Engine. There is a writable /tmp directory (https://cloud.google.com/appengine/docs/standard/java-gen2/using-temp-files). If your app on startup first copies the db.sqlite3 file to /tmp/db.sqlite3 and references this path as database path, it will work.
The following problems are connected with this approach:
This directory is "in-memory". So if you want to use really large sqlite file, you may face problems with RAM.
Each node of the app gets its own copy of the database. If you save something on one node, these changes will not be seen by other nodes. And the new data will be lost if the app scales to 0.

Categories

Resources