Android 位数 returns 无
Android Digits returns nothing
为什么Android数字验证后不总是returnonSuccess或onFalure?它只是完成 DigitsActivity 并且什么都不做,但有时它没问题,我收到 onSuccess。
public void initForm(){
Digits.getSessionManager().clearActiveSession();//
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());
}
好的,我不知道自定义按钮和自定义 authcallback 有什么问题。使用 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) {
}
});
我遇到了同样的问题,phoneNumber 也像 this question 一样返回为 null。我在使用自定义按钮时解决了这个问题。主要问题是没有正确清除数字会话并在每次点击时在 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();
}
}
@rallat 在这里评论https://github.com/twitter/digits-android/issues/6
他们将 authcallback 更改为弱引用,以避免内存泄漏。
只需在您的上下文中创建回调变量,f.e:
AuthCallback authCallback = new AuthCallback() {
@Override
public void success(DigitsSession session, String phoneNumber) {
// Do something with the session
Log.d(TAG, "success: " + phoneNumber);
}
@Override
public void failure(DigitsException exception) {
// Do something on failure
Log.d(TAG, "failure: ");
//show error or somthing
}
};
并将其传递给您的构建器:
digitsButton.setCallback(authCallback);
为什么Android数字验证后不总是returnonSuccess或onFalure?它只是完成 DigitsActivity 并且什么都不做,但有时它没问题,我收到 onSuccess。
public void initForm(){
Digits.getSessionManager().clearActiveSession();//
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());
}
好的,我不知道自定义按钮和自定义 authcallback 有什么问题。使用 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) {
}
});
我遇到了同样的问题,phoneNumber 也像 this question 一样返回为 null。我在使用自定义按钮时解决了这个问题。主要问题是没有正确清除数字会话并在每次点击时在 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();
}
}
@rallat 在这里评论https://github.com/twitter/digits-android/issues/6
他们将 authcallback 更改为弱引用,以避免内存泄漏。
只需在您的上下文中创建回调变量,f.e:
AuthCallback authCallback = new AuthCallback() {
@Override
public void success(DigitsSession session, String phoneNumber) {
// Do something with the session
Log.d(TAG, "success: " + phoneNumber);
}
@Override
public void failure(DigitsException exception) {
// Do something on failure
Log.d(TAG, "failure: ");
//show error or somthing
}
};
并将其传递给您的构建器:
digitsButton.setCallback(authCallback);