gpt4 book ai didi

java - Android Digits 什么都不返回

转载 作者:行者123 更新时间:2023-11-30 08:39:56 25 4
gpt4 key购买 nike

为什么 Android Digits 在号码验证后并不总是返回 onSuccess 或 onFalure?它只是完成 DigitsActivity 并且什么都不做,但有时它没问题并且我收到 onSuccess。

public void initForm(){
Digits.getSessionManager().clearActiveSession();// http://stackoverflow.com/questions/31679089/fabric-digits-returns-a-null-object-of-phonenumber-after-otp-verification-on-and
DigitsAuthConfig.Builder digitsAuthConfigBuilder = new DigitsAuthConfig.Builder()
.withAuthCallBack(new AuthCallback() {
@Override
public void success(DigitsSession digitsSession, String s) {
Toast.makeText(LoginActivity.this, s, Toast.LENGTH_LONG).show();
TwitterAuthToken token = (TwitterAuthToken)digitsSession.getAuthToken();
DigitsOAuthSigning oauthSigning = new DigitsOAuthSigning(SapronApplication.conf(), token);
Map<String, String> authHeaders = oauthSigning.getOAuthEchoHeadersForVerifyCredentials();
requestToken(authHeaders.get("X-Verify-Credentials-Authorization"));

}

@Override
public void failure(DigitsException e) {
Toast.makeText(LoginActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
})
.withPhoneNumber("+7");


Digits.authenticate(digitsAuthConfigBuilder.build());
}

最佳答案

我遇到了同样的问题,并且 phoneNumber 返回为 null,如 this question .我在使用自定义按钮时解决了这个问题。主要问题是没有正确清除数字 session 并在每次点击时在 withAuthCallBack() 中设置新的 AuthCallback。下面给出了解决我的问题的代码。希望它能帮助那些需要为数字使用自定义按钮的人......

findViewById(R.id.customDigitsButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
verifyMobileUsingDigits();
}
});

private AuthCallback authCallback;
public void verifyMobileUsingDigits(){
logoutFabricDigits("verifyMobileUsingDigits");// manual deletion of all digit sessions, as only Digits.getSessionManager().clearActiveSession() did not helped me.....
if(authCallback == null){
authCallback = new AuthCallback() {
@Override
public void success(DigitsSession session, String phoneNumber) {
Toast.makeText(getApplicationContext(), "Authentication successful for " + phoneNumber, Toast.LENGTH_LONG).show();
}

@Override
public void failure(DigitsException exception) {
Toast.makeText(getApplicationContext(), "Authentication failure", Toast.LENGTH_LONG).show();
}
};
}
DigitsAuthConfig.Builder digitsAuthConfigBuilder = new DigitsAuthConfig.Builder()
.withAuthCallBack(authCallback)
.withPhoneNumber("+880")
.withEmailCollection(false)
.withThemeResId(R.style.CustomDigitsTheme);
Digits.authenticate(digitsAuthConfigBuilder.build());
}

public static void logoutFabricDigits(String TAG){
try {
Map<Long, DigitsSession> digitsSessionMap = Digits.getSessionManager().getSessionMap();
if(digitsSessionMap != null){
Set<Long> digitIdSet = new HashSet<>(digitsSessionMap.keySet());
for(Long digitId : digitIdSet){
DigitsSession digitsSession = digitsSessionMap.get(digitId);
if(digitsSession != null){
Digits.getSessionManager().clearSession(digitsSession.getId());
}
}
}
Digits.getSessionManager().clearActiveSession();
} catch (Exception e) {
e.printStackTrace();
}
}

关于java - Android Digits 什么都不返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35917199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com