强制关闭 GoogleApiClient.connect()
Force close on GoogleApiClient.connect()
我不知道为什么我的应用程序在单击 g+singin 按钮 时会强制关闭。我刚刚实现了一个 g+ 登录按钮,点击它会调用 GoogleApiClient.connect() 方法。但是如果我评论 GoogleApiClient.connect() 方法,应用程序不会强制关闭。实际上,如果连接失败,应该调用 onConnectionFailed() 方法,但强制关闭。
我已将错误消息作为图像放在底部........
package com.playservices.murali.playservices;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
import com.google.example.games.basegameutils.BaseGameUtils;
public class MainActivity extends ActionBarActivity implements
View.OnClickListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "asdf";
private GoogleApiClient mGoogleApiClient;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInFlow = true;
private boolean mSignInClicked = false;
private static int RC_SIGN_IN = 9001;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
// start the asynchronous sign in flow
mSignInClicked = true;
mGoogleApiClient.connect();
}
else if (view.getId() == R.id.sign_out_button) {
// sign out.
mSignInClicked = false;
Games.signOut(mGoogleApiClient);
// show sign-in button, hide the sign-out button
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
}
}
尝试将我的代码移植到你的代码中http://pastebin.com/gAspppbh你几乎遗漏了一些东西!
有些设备没有提供 GoogleApiClient 来获取位置。我已经遇到过这个问题。所以我可以将 GoogleApiClient 更改为 FusedLocationProviderClient.I 来解决我的问题。有关此问题的更多信息,请访问下面 link
我不知道为什么我的应用程序在单击 g+singin 按钮 时会强制关闭。我刚刚实现了一个 g+ 登录按钮,点击它会调用 GoogleApiClient.connect() 方法。但是如果我评论 GoogleApiClient.connect() 方法,应用程序不会强制关闭。实际上,如果连接失败,应该调用 onConnectionFailed() 方法,但强制关闭。 我已将错误消息作为图像放在底部........
package com.playservices.murali.playservices;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
import com.google.example.games.basegameutils.BaseGameUtils;
public class MainActivity extends ActionBarActivity implements
View.OnClickListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "asdf";
private GoogleApiClient mGoogleApiClient;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInFlow = true;
private boolean mSignInClicked = false;
private static int RC_SIGN_IN = 9001;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
@Override
protected void onStart()
{
}
@Override
protected void onStop()
{
}
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
// start the asynchronous sign in flow
mSignInClicked = true;
mGoogleApiClient.connect();
}
else if (view.getId() == R.id.sign_out_button) {
// sign out.
mSignInClicked = false;
Games.signOut(mGoogleApiClient);
// show sign-in button, hide the sign-out button
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.sign_out_button).setVisibility(View.GONE);
}
}
}
尝试将我的代码移植到你的代码中http://pastebin.com/gAspppbh你几乎遗漏了一些东西!
有些设备没有提供 GoogleApiClient 来获取位置。我已经遇到过这个问题。所以我可以将 GoogleApiClient 更改为 FusedLocationProviderClient.I 来解决我的问题。有关此问题的更多信息,请访问下面 link