Java:
if (resultCode == RESULT_OK) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
userName = Objects.requireNonNull(user).getDisplayName();
profileNameEdit.setText(userName);
userEmail = user.getEmail();
profileEmailEdit.setText(userEmail);
String userID = user.getUid();
除了user.getUid()
之外,一切都OK。该请求仅返回任何内容(不为null,简单为空)。
如何获取用户ID?
答案 0 :(得分:0)
Hmmm ...字符串userID为空,然后将其从文本输入到TextView。关闭答案。
答案 1 :(得分:0)
尝试执行此操作:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// User is signed in
userName = user.getDisplayName();
profileNameEdit.setText(userName);
userEmail = user.getEmail();
profileEmailEdit.setText(userEmail);
String mUid = user.getUid();
//Set text here not only get the Uid
}
else {
Toast.makeText(ListActivity.this, "No user logged in", Toast.LENGTH_SHORT).show();
}
如果它不起作用,请尝试让Uid
这样做:
String mUid=FirebaseDatabase.getInstance().getReference().child("Users")
.child(user.getUid());
或
String mUid=FirebaseDatabase.getInstance().getReference().child("Users")
.child(FirebaseAuth.getInstance()getCurrentUser().getUid());