Anton Kazakov Anton Kazakov - 7 months ago 58
Java Question

Android Digits returns nothing

Why Android Digits do not always return onSuccess or onFalure after number verification? It just finish DigitsActivity and do nothing, but sometimes its okay and I receive 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());
}

Answer

Okay i don't know what's wrong with custom button and custom authcallback. Solved problem by using DigitsAuthButton.

  digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button);
   // digitsButton.setAuthTheme(R.style.AppTheme2);
    digitsButton.setCallback(new AuthCallback() {
        @Override
        public void success(DigitsSession digitsSession, String s) {
            new MaterialDialog.Builder(LoginActivity.this)
                    .progress(true, 0)
                    .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) {

        }
    });