I am using Firebase and have a signup / login activities working fine but I also want each user to update a username. It seems I am unable to run:
firebaseR
Need to add AuthStateListener.
mAuth=FirebaseAuth.getInstance();
mAuthListener=new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser()==null){
//Your action here
}
}
};
A simple way to check if there is any update for Firebase dependency:
FirebaseAuth.getInstance().getUid();
This API seems to have been removed in Firebase 12.0.0
Use this instead
FirebaseAuth.getInstance().getCurrentUser().getUid();
with the appropriate null check, or use Firebase 12.0.1 where i now seems to have @Hide annotation
Add this after the Main Activity class
Firebase firebaseAuth;
DatabaseReference reference;
Add anywhere in onCreate
String usern;
usern = firebaseAuth.getInstance().getCurrentUser().getUid();
Upload to Firebase to their repective children
reference=FirebaseDatabase.getInstance()
.getReference().child("Patients")
.child("Patient" + usern).child("Pres");
In your app build.gradle, add this to your dependencies
compile 'com.google.firebase:firebase-auth:9.4.0'
import com.google.firebase.auth.FirebaseAuth;
...
...
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
//Go to login
}
else{
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
}