Can i access Firebase Storage without Realtime Database& - android

I'm using Firebase Realtime Database do store and display data inside RecyclerView. Now i have a lot of images(54). I stored them in Firebase Storage. Here is my question, can i access them without created database nodes with they're access token in them to display them in RecyclerView?
Right now i'm using Firebase Realtime Database to get they're access token and to display them in RecyclerView like show in screenshot

Yes, if you make use of the appropriate Cloud Storage methods of the Firebase Client SDK for Android. This would allow you to retrieve download URLs for objects stored in Cloud Storage and then display them in your app without the need of a database.
However, the purpose of using either the Realtime or Cloud Firestore databases is to generate a single access token for that resource that can be shared and reused by multiple users at once. This greatly improves loading times for your application as you don't have to generate an access token for each client accessing the object.
While you could store these URLs inside of Cloud Storage itself in its own static object (e.g. gs://your-app.appspot.com/shared/images.json) using the appropriate permissions, it has the trade-off of not being easily editable and if you revoke the access token for it, you may break apps that rely on it.
As you are likely already making use of the Realtime Database in your app already (for user data, preferences, and other information), this benefit of storing these URLs in your database of choice outweighs the negatives.

Related

How to save a part of firebase realtime database in offline mode

I wanted to store the specific path in Firebase database (JSON) in local phone storage, not all data at the realtime-Firebase database. Say I have a news-feed path for each user in my Firebase-database and I want to save only the news-feed which is specified for the user instead of loading whole useless data on the local storage of user's mobile.
I read this paragraph from the official Firabase site which mentioned that
The Firebase Real-time Database synchronizes and stores a local copy of the data for active listeners. In addition, you can keep specific locations in sync.
DatabaseReference scoresRef = FirebaseDatabase.getInstance().getReference("scores");
scoresRef.keepSynced(true);
If this is the solution to my question, then I can use this line directly without writing that line
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Those two bits of code are not really related. They don't do the same thing.
keepSynced(true) effectively keeps a listener active on the given reference, from the moment it's called, for as long as the app is running, so that the local version of the data is always in sync with the remote version on the server.
setPersistenceEnabled(true) just activates local caching of the data read by the SDK. When persistence is enabled, the app can still query data previously read. It takes effect for all data read by the SDK. While persistence is enabled, you can't control which data is cached - all read data is cached up to 10MB max. When the max is reached the oldest data will be evicted from the cache.
According to me the best way will be to parse the Firebase JSON data and map it into an object and then save only data that you need in a local storage (News-feed in your case), and then access it later whenever you need it.
For this, you can use Paper DB as a local storage to store specific data and use it whenever you need to. It stores data as a key value pair so you can access your data with the same key you inserted it with in the database. (Just like shared preferences work).
It stores data as cache in your local storage and uses Kryo serialization framework which is pretty fast for I/O operations.
Or you can also use Room (a google library) with SQLite to achieve this task.
Haven't tried Room but i think it will suite your purpose.
Here's the official documentation for Room

How to display data uploaded by different users in a general list through firebase

I am making an app in which the user will authenticate themselves and store information, say related to food detail. Firebase will store this information corresponding to each userID. I want that whenever any user opens the app, he should see a list of all the food details uploaded by different users. I know only how to access data of the current user. Even for a particular user, i want to access a given field of all users present in Firebase realtime database.
From all the info available from your question, here are my points in my experience i would have done.
you will have to have these data for the food stored in a common location where your security rules permits for read and write but only if the user is authenticated
realtime database security rules documentation
next, I will keep all these food data in the common location as earlier said and a condensed version of it at each user's hierarchical level with the same identifier( document id or reference) as in the common location for easy retrieval should I want to.
working with a list of data in firebase realtime database at this stage, assuming you will be loading it into a listview/recyclerview, on receival of new object, you can just load it into your adapter and you are good to go.
Even for a particular user, i want to access a given field of all users present in Firebase realtime database.
Just make them security rules to that field readable by any logged in user and then, use the following link to know how to access the data.
reading data from firebase realtime database. Hope this helps. If you want more explanation, give more details on your use case and the hierarchical structure of your database.

Android: using Firebase to store static data

I'm developing an android application that will allow users to find informations about the streets in my city. They will be able to register and save some streets as "favourites".
My question is, how can I use Firebase to store the streets data considering that they won't change overtime?
The Firebase data model is not well suited to storing arrays (or Java List objects). See this blog post explaining the behavior you get. Instead of storing a List, follow the Firebase documentation's approach for storing collections. This will indeed store it as a map, which is the correct approach precisely .
That depends mostly on how you want to read the data.
If you always load all of the street data, then you might as well store it as a file on Firebase Hosting. That'll be a lot cheaper, and perform better (since the data is cached on a CDN).
If the app loads parts of the data, but it's not very dynamic, you could split the data into multiple files and still store those on Firebase Hosting.
If users sometimes update the data, but it's still hardly queries by the apps, consider storing it in Cloud Storage through the Firebase SDK. The files are available to all of your users that way.
If you want advanced querying of the data, consider storing it in the Firebase Realtime Database or in Cloud Firestore.

How do I synchronize Firebase Storage and Database?

I have yet to find any good documentation to tell me how to manage this issue. Is there any guidance someone can reference for this issue?
For an Android app, I have started using Google Firebase Storage along with my realtime Database, and I have a question on how to ensure file uploads and database updates happen in the proper order.
Previously, I was encoding an audio file to a string and uploading it to FB Database along with other related data as a single hash map to ensure consistency. The related data that is being stored is a POJO relating to what users can access the audio, the path where the audio is stored in the database, and more.
My new set up is first to upload the audio file to FB Storage, and, once the file is uploaded, trigger a FB Database update for the related data. Once the database listener indicates completion, the app moves to a different activity.
I am concerned that this two step process is unstable (user leaves the activity before both tasks are done, Storage upload is interrupted and Database update never occurs, etc.). If the Database information isn't updated, the other users won't be notified that the audio file is online and they won't have the path to reference it stored in the database.
What is the proper order for structuring simultaneous Storage and Database uploads in the new Google Firebase?
Thanks,
Andy
Not sure why there are no solid answers for this yet. Anyway, I have faced very similar problems and eventually resorted with nested-updates using completion blocks (exactly how you described in your question).
Very recently, Firebase introduced cloud functions. I am utilizing this to watch the files that are uploaded, and then create a metadata entry into FB Database with the cloud function.
Basically, I use childByAutoId() to generate a key which is used to name the file. For example, profile pictures are saved at "gs://bucket-id/profile_pictures/somerandomkey.jpeg". Then I create a metadata entry into my FB database with cloud functions by utilizing the key from the filename.
I am not sure if there is a better way, but using cloud functions surely seems like a better approach than the nested-updates approach.
You can upload image using Firebase Storage, in success you get a downloadable URL of that image. Then put all the values in the custom object including that image URL and save that object in RealTime Database of Firebase.
And you can use the image URL by retrieving object from RealTime Database.

Protecting Local SQLite Database (Android Application)

We have an Android application which stores its data in a local SQLite database; primarily for performance, but also to allow for working off-line (as we are often in areas with low signal).
At the moment, the data is stored in encrypted format (passed down from our web servers), but this in itself causes a performance issue, where for example, if we want to search records for a particular "surname", we need to decrypt ALL of the data, rather than using a straight SQL query, to include where surname='Smith'
We cannot (as it currently stands) store the data in a more friendly 'open-format', as it's possible to 'root' the device, take a copy of the MySQL database, open it and read the data.
Is there the means (perhaps someone can provide an example) to either password protect the local SQLite database or somehow apply encryption, so that we can (from an application perspective) have the database available in open format, but so that if any would-be hacker got hold of the device and rooted it ... they would have a hard time reading our data?
I have searched for a suitable solution and cannot find any options for the SQLite database, any 3rd party software or any examples of code that do this.
SqlCipher, this will might work in your case
Remote Storage:
Your data is sensitive and needs to be accessed by the user on the go from different devices. If your app is a good one then the above line will hold true.
Security + Remote access from any device says you maintain your dB on a remote server.
Your flow can be :
User login --> Token --> Auth Token in every call --> Process request and get/put data in/from dB
Local Storage:
Let's say that you only want to store data locally and don't want to store it on the server. For this you can use public-key cryptography
You can use a public Key in your app to encrypt the data and store it. Now, you want to access the data. Request the private key from the server and decrypt it.
Again, to get access to private key you should use some form of authorization (or anyone can access your key).
Without the private key, even if a hacker roots the phone and gets his/her hands on the dB, the data would be useless.

Categories

Resources