【发布时间】:2017-02-25 00:24:02
【问题描述】:
我想使用 Play 游戏服务,所以我使用带有 Games.API 的 GoogleApiClient 并调用方法 connect()。但是它总是在 onConnectionFailed() 中给出错误 RESOLUTION_REQUIRED。
public class MainActivity extends Activity implements
ConnectionCallbacks,
OnConnectionFailedListener {
GoogleApiClient googleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build(); }
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
//ConnectionResult{statusCode=RESOLUTION_REQUIRED, resolution=PendingIntent{dd739ef: android.os.BinderProxy@624acfc}, message=null}
}
但如果我使用 Auth.API 而不是 Games.API,则连接成功并调用方法 onConnected()。
public class MainActivity extends Activity implements
ConnectionCallbacks,
OnConnectionFailedListener {
GoogleApiClient googleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Auth.GOOGLE_SIGN_IN_API)
.build();
}
@Override
public void onConnected(Bundle connectionHint) {
//Success
}
我用的是模拟器,模拟器中播放服务的版本是10.0,所以我在gradle build中也设置了10.0版本
compile 'com.google.android.gms:play-services-games:10.0.0'
compile 'com.google.android.gms:play-services-auth:10.0.0'
我在这里Google Play fails to connect, statusCode=RESOLUTION_REQUIRED发现了同样的问题,但是作者没有得到任何答案。
【问题讨论】:
标签: android google-play-services google-api-client