[英]GoogleAPIClient not connecting properly?
我正在尝试按照本指南连接mGoogleAPIClient。 当我进行调试时,会弹出一个小窗口,询问我要使用哪个googleplus帐户登录。 一旦我选择主帐户并单击“确定”,它就会从那里停止,并且绝对不起作用。 没有错误消息,警告,信息,什么都没有。
我的来源:公共类MainMenu_Activity扩展Activity实现了GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {
private Button btnStart;
private Button btnSubmit;
private Button btnHOF;
private GoogleApiClient mGoogleApiClient;
public static int REQUEST_LEADERBOARD = 100;
// Request code to use when launching the resolution activity
private static final int REQUEST_RESOLVE_ERROR = 1001;
// Bool to track whether the app is already resolving an error
private boolean mResolvingError = false;
private static final String STATE_RESOLVING_ERROR = "resolving_error";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainmenu);
mResolvingError = savedInstanceState != null
&& savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
this.mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
protected void onStart() {
super.onStart();
if (!mResolvingError) { // more about this later
mGoogleApiClient.connect();
}
}
@Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(Bundle connectionHint) {
// Connected to Google Play services!
// The good stuff goes here.
System.out.println("CONNECTED!");
}
@Override
public void onConnectionSuspended(int cause) {
// The connection has been interrupted.
// Disable any UI components that depend on Google APIs
// until onConnected() is called.
System.out.println("SUSPENDED!");
}
@Override
public void onConnectionFailed(ConnectionResult result) {
System.out.println("Connection Failed - mResolvingError=" + mResolvingError);
if (mResolvingError) {
System.out.println("Connection Failed - Already attempting to resolve...");
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
System.out.println("Connection Failed - resolving now...");
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (IntentSender.SendIntentException e) {
System.out.println("Connection Failed - Exception...");
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
Dialog errDia = GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 1);
errDia.show();
mResolvingError = true;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, mResolvingError);
}
}
如您所见,我标记了某些地方以遵循该程序。 好吧,这就是logcat记录的内容:
06-02 17:52:48.175 2302-2302 / com.dudewithfacial.game.gamebase I / System.out:连接失败-mResolvingError = false 06-02 17:52:48.175
2302-2302 / com.dudewithfacial.game.gamebase I / System.out:连接失败-立即解决...
我一步一步地遵循指南:(显然不是,我在做什么错的Stackoverflow-Gurus?男孩,非常感谢!
NVM,发现我不能使用Launchmode,SingleUser,SingleInstance。 还没有配置一些请求的API,例如“ .addApi(Plus.API)”
问题已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.