为什么在Android Google+;认证?
下面是我对G+身份验证样板文件的实现。当按下按钮时,子类调用resolveSignInErrors(),但是实现无法工作。问题是当调用resolveSignInErrors()时,mConnectionResult为null,因此不会发生任何事情 我希望在onConnectionFailed()中设置mConnectionResult,但是没有调用它,尽管调用了GoogleAppClient.connect()。为什么不调用onConnectionFailed()呢 我觉得这个API完全令人困惑为什么在Android Google+;认证?,android,google-plus,google-play-services,Android,Google Plus,Google Play Services,下面是我对G+身份验证样板文件的实现。当按下按钮时,子类调用resolveSignInErrors(),但是实现无法工作。问题是当调用resolveSignInErrors()时,mConnectionResult为null,因此不会发生任何事情 我希望在onConnectionFailed()中设置mConnectionResult,但是没有调用它,尽管调用了GoogleAppClient.connect()。为什么不调用onConnectionFailed()呢 我觉得这个API完全令人困惑
public class GooglePlusActivity extends MyActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
private ConnectionResult mConnectionResult;
boolean mIntentInProgress = false;
final int RC_SIGN_IN = 0;
protected boolean mSignInClicked;
@Override
protected void onCreate(Bundle savedInstanceState) {
initialiseGoogleApiClient();
super.onCreate(savedInstanceState);
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
super.onStop();
}
protected GoogleApiClient getGoogleApiClient() {
return mGoogleApiClient;
}
protected void initialiseGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void onConnected(Bundle connectionHint) {
mSignInClicked = false;
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (!mIntentInProgress) {
mConnectionResult = connectionResult;
if (mSignInClicked) {
resolveSignInError();
}
}
}
protected void resolveSignInError() {
Toast.makeText(this, "resolveSignInError", Toast.LENGTH_SHORT).show();
if (mConnectionResult!=null && mConnectionResult.hasResolution()) {
Toast.makeText(this, "inside if", Toast.LENGTH_SHORT).show();
try {
Toast.makeText(this, "inside try", Toast.LENGTH_SHORT).show();
mIntentInProgress = true;
mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
mIntentInProgress = false;
getGoogleApiClient().connect();
}
}
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
if (responseCode != RESULT_OK) {
mSignInClicked = false;
}
mIntentInProgress = false;
if (!getGoogleApiClient().isConnecting()) {
getGoogleApiClient().connect();
}
}
}
}
我看不出为什么它不能用给定的代码得到调用,你确定这不是MinentInProgress no设置正确吗?还是只是连接正确?在您批准应用程序一次后,后续调用应成功,直到用户取消对应用程序的授权。