我想使用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上发现了同样的问题,但作者没有得到任何答案。
发布于 2017-02-26 00:24:06
基于ConnectionResult,错误代码为RESOLUTION_REQUIRED
完成连接需要某种形式的解决方案。将有一个解决方案可用于启动
startResolutionForResult(Activity, int)。如果返回的结果为RESULT_OK,则进一步的连接尝试应完成或继续到需要解决的下一个问题。
除此之外,您可能还希望检查应该如何处理Manually managed connections中讨论的连接故障。如上所述,
当您的应用程序收到对
onConnectionFailed()回调的调用时,您应该在提供的ConnectionResult对象上调用hasResolution()。如果返回true,您的应用程序可以通过在ConnectionResult对象上调用startResolutionForResult()来请求用户立即采取措施来解决错误。在这种情况下,startResolutionForResult()方法的行为与startActivityForResult()相同,并启动一个适合于上下文的活动,以帮助用户解决错误。
https://stackoverflow.com/questions/42450448
复制相似问题