This is for a main code for all firebase setup need to be add in code
private FirebaseDatabase database = FirebaseDatabase.getInstance();
private DatabaseReference mDatabase = database.getInstance().getReference("food_level");
private DatabaseReference mDatabase1 = database.getInstance().getReference("bubbler");
//decalre the progressBar pb = (ProgressBar) findViewById(R.id.progressBar3);
// Read from the database in rea time mDatabase.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // This method is called once with the initial value and again // whenever data at this location is updated. value = dataSnapshot.child("current_level").getValue(long.class); Log.d(TAG, "Value is: " + value);
////get the value in realtime and update the progressbar from that value
pb.setProgress((int)value);
//System.out.println("robinroy peter"+value.FoodLevel);
}
@Override public void onCancelled(DatabaseError error) {
// Failed to read value Log.w(TAG, "Failed to read value.", error.toException());
}
});
}
////set the value in firebase databse
mDatabase1.setValue(mSwitch.getTextOn().toString());
Comments
Post a Comment