我尝试按照this Guide连接mGoogleAPIClient。 当我调试时,一个小窗口弹出询问我想要登录的googleplus帐户。一旦我选择了我的主帐户并单击“确定”,它就会从那里停止并且什么都不做。没有错误消息,警告,信息,没有任何内容。
我的来源: 公共类MainMenu_Activity extends 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? Thx男孩,真的很感激!
答案 0 :(得分:0)
NVM,想通了我无法使用Launchmode,SingleUser,SingleInstance。 还没有配置一些请求的API,例如“.addApi(Plus.API)”
问题已解决。