2016-10-09 41 views

回答

6

Firebase身份驗證數據已針對所有活動提供。你只需要查看它的API。

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 

如果不知道用戶是否在尚未簽署這樣做,使用addAuthStateListener()聽衆:

FirebaseAuth.getInstance().addAuthStateListener(new FirebaseAuth.AuthStateListener() { 
    @Override 
    public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
     FirebaseUser user = firebaseAuth.getCurrentUser(); 
     if (user != null) { 
      // User is signed in 
      Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); 
     } else { 
      // User is signed out 
      Log.d(TAG, "onAuthStateChanged:signed_out"); 
     } 
     // ... 
    } 
}); 

兩個

如果您知道的用戶已登錄來自documentation on getting the current user