I want to save the current date/time in specific field when I add new value to Firebase Realtime Database via control panel.
How can I achieve that?
Please
Alex Mamo is right but then this is how you should pass incase you call it from a model class
public class FirebMessage {
public String message;
public String senderPhoneNumber;
public String receiverPhoneNumber;
public Map time;
public FirebMessage() {
}
public FirebMessage(String message, String senderPhoneNumber, String receiverPhoneNumber, Map time) {
this.message = message;
this.senderPhoneNumber = senderPhoneNumber;
this.receiverPhoneNumber = receiverPhoneNumber;
this.time = time;
}
Then consume as follows
private void writeNewMessage(String message, String receiver,String sender) {
FirebMessage firebMessage = new FirebMessage(message, receiver,sender,ServerValue.TIMESTAMP);
mDatabase.child("messages").push().setValue(firebMessage, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError != null) {
Log.e(TAG,"Data Not saved");
} else {
Log.e(TAG,"Data saved successfully");
}
}
});
}