Skip to content Skip to sidebar Skip to footer

Assign A Firebase Database Url(string) To A Database Reference Variable?

I'm trying to assign a string that contains a url for a place in my database to a DatabaseReference type. Example: String strRef = 'my database url'; DatabaseReference ref = //here

Solution 1:

If you get a full URL to a location in the database from somewhere, you can create a DatabaseReference to that location with:

Stringurl="https://<your-project>.firebaseio.com/path/to/data";
DatabaseReferenceref= FirebaseDatabase.getInstance().getReferenceFromUrl(url);

So the above works if your URL starts with https://<your-project>.firebaseio.com/.

If you get a full path instead, you'd use:

Stringpath="/path/to/data";
DatabaseReferenceref= FirebaseDatabase.getInstance().getReference(path);

Post a Comment for "Assign A Firebase Database Url(string) To A Database Reference Variable?"