這聽起來像您正在尋找Firebase的匿名身份驗證。用戶啓動應用程序的第一次,你在再簽收:
FirebaseAuth.getInstance().signInAnonymously()
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInAnonymously:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInAnonymously:failure", task.getException());
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// ...
}
});
這對他們來說並存儲生成一個唯一的UID,在您的應用程序的共享偏好。
他們下一次啓動應用程序,其用戶信息被讀取,你可以檢測到用戶使用:
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
updateUI(currentUser);
見獲取更多信息Firebase Authentication documentation。這也可在iOS。