【发布时间】:2020-12-24 22:05:27
【问题描述】:
我正在使用 MVVM。我想在应用程序中实现 Firebase Auth。但要实现它,我需要在我的 repo 类中有一个活动上下文。我如何从 ViewModel 中获取它或者有什么简单的方法可用?
这是我需要实现的 firebase 代码:
PhoneAuthProvider.getInstance().verifyPhoneNumber("+91"+phone, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
(Activity) context, // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential)
{
signInWithPhoneAuthCredential((Activity)context,phoneAuthCredential);
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
setLoginFailed(e);
}
@Override
public void onCodeSent(@NonNull String s, @NonNull
PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
loginResponse.setOnProgress(false);
loginResponse.setStatus(true);
loginResponse.setCodeVerified(false);
loginResponseLiveData.setValue(loginResponse);
verificationId =s;
}
});
【问题讨论】:
标签: android firebase mvvm firebase-authentication