How do i set text to firebase database using Java

276 views
Skip to first unread message

mapeven...@gmail.com

unread,
Dec 5, 2014, 1:12:01 PM12/5/14
to fireba...@googlegroups.com

I want to send a text area (message) into the Fire base database. I can save a string but it does not work with a text area here is my code:

                Map<String, Object> updates = new HashMap<String, Object>();
                updates.put("Your Message: ", textArea);
                f.setValue(updates);

So yea i want to save a text area to the firebase database, I also want to know how I can send it to a specific entity for example.

save at Name: mystring or at ID: myid if there is a way to use JSON with java or something to send data, please let me know thanks. I am new to fire base.

Jonny Dimond

unread,
Dec 8, 2014, 1:44:23 PM12/8/14
to fireba...@googlegroups.com
Hi,

we use Java's types to represent JSON in Java. For example a JSON string will be a Java String, a JSON object will be a Map<String, Object>, a JSON array a List<Object>.

To save data to Firebase you need to use the corresponding types. For example, if you want to save a message with an id or key of "id-123" to Firebase from a TextView:

Firebase ref = new Firebase(...);
ref.child("id-123").setValue(mTextView.getText().toString());

If you want to save more things for your message, your example is a good starting point:
Map<String, Object> message = new HashMap<String, Object>();
message.put("message", textArea.getText().toString());
// any other things you want to store in this here, e.g. user
f.setValue(message);

This will then store something like
{ "message": ... }
in your in your Firebase.

Does that answer your question?

Jonny 
Reply all
Reply to author
Forward
0 new messages