I am fairly new to Android development. I am working on an app which I have connected to a firebase database and everything works fine. Now I am trying to connect a device which will send a like an attendance details of each users when they clock in on that device to the firebase database. Do I need a http interface to do this or an API
Try this
Declare few variables:
private FirebaseUser user;
private FirebaseDatabase database;
private DatabaseReference mRef;
Initialise them inside onCreate or somewhere:
user = FirebaseAuth.getInstance().getCurrentUser();
database = FirebaseDatabase.getInstance();
mRef = database.getReference("users").child(user.getUid()).child("attendance"); //different path for each user
Add value event listener
mRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Integer attendance = dataSnapshot.getValue(Integer.class);
attendance++;
myRef.setValue(attendance);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
No you don't need any http interface to read and write value to firebase database . You can refer to official documentation here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.