我正在使用firebase来显示我的餐厅的在线和离线状态,并且我还将通过匿名用户登录每5秒钟更新一次该状态,因此用户登录需要播放服务,因为我已经使用Google凭据登录了该设备,当它可以正常工作时我在多个设备中使用相同的凭据,但帐户中没有两步验证,但是如果某些帐户有两步验证,餐厅数据未更新,这是我的代码
private void signInAnnomymously() {
try {
if (mAuth == null)
mAuth = FirebaseAuth.getInstance();
mAuth.signInAnonymously()
.addOnCompleteListener(mAct, 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
Lg.d(TAG, "signInAnonymously:success");
FirebaseUser user = mAuth.getCurrentUser();
if (pref.isLoggedIn(instance)) {
// start handler for periodic online status
executeHandler();
}
} else {
// If sign in fails, display a message to the user.
Lg.w(TAG, "signInAnonymously:failure", task.getException());
// Toast.makeText(instance, "Authentication failed.",Toast.LENGTH_SHORT).show();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
这是excuteHandler
private void executeHandler() {
if (handler == null && runnable == null) {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
if (pref.isLoggedIn(instance)) {
setOnlineOfflineFireBase(AppConstants.STATUS_ONLINE);
}
handler.postDelayed(this, EVERY_FIVE_SECOND);
}
};
}
else {
handler.postDelayed(runnable, EVERY_FIVE_SECOND);
}
}