本文介绍了为什么应用程序在GoogleApiClient.connect()上被强制关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

app强制关闭调用GoogleApiClient.connect()方法,至少如果它没有连接它应该调用onConnectionFailed,但不知道为什么我的应用程序正在强制关闭。当我评论GoogleApiClient.connect()方法时,它不会强制关闭........从几个小时一起尝试。



这是我的代码

  package com.playservices.murali.playservices; 

导入android.support.v7.app.ActionBarActivity;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;

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;


public class MainActivity extends ActionBarActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games .SCOPE_GAMES)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.build();


@Override
protected void onStart()
{
super.onStart();
mGoogleApiClient.connect();
}

保护无效onStop()
{
super.onStop();
//mGoogleApiClient.disconnect();
}
@Override
public void onConnected(Bundle bundle){

}

@Override
public void onConnectionSuspended int i){

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult){


}

android的错误消息日志位于图片

解决方案

这个错误的常见来源很少:


  1. 您是否已在 AndroidManifest.xml中正确定义您的Play游戏应用ID ?它应该如下所示:

在您的应用程序标记中:

 < meta-data android:name =com.google.android.gms.game.gifs.APP_ID
android:value =@ string / app_id/>




  1. 在Google Play开发者控制台,您是否在测试人员选项卡中添加了所有正确的帐户?任何希望在发布之前使用您的应用程序的Google帐户都必须在此处注册。

  2. 您是否为您的应用程序创建了一个客户端ID?请务必在 Google Play开发者控制台中通过链接的应用程序选项卡执行此操作,而不是 Google Developer Console


the app force closes on calling GoogleApiClient.connect() method, atleast if it doesn't connect it should call onConnectionFailed, but dont know why my app is getting force closed. when i comment GoogleApiClient.connect() method it doesn't force close........ trying from hours together .

this is my code

  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 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;


  public class MainActivity extends ActionBarActivity implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();
}

@Override
protected void onStart()
{
    super.onStart();
    mGoogleApiClient.connect();
}

protected void onStop()
{
    super.onStop();
    //mGoogleApiClient.disconnect();
}
@Override
public void onConnected(Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}
}

the error message log for the android is below image

解决方案

There are a few common sources of this error:

  1. Do you have your Play Games App ID properly defined in your AndroidManifest.xml? It should look like this:

In your application tag:

<meta-data android:name="com.google.android.gms.games.APP_ID"
          android:value="@string/app_id" />
  1. In the Google Play Developers console, have you added all of the correct accounts in the Testers tab? Any Google account that wants to use your application before it is published must be registered here.

  2. Have you (properly) created a Client ID for your application? For Games make sure to do this in the Google Play Developer Console through the Linked Apps tab and not the Google Developer Console.

这篇关于为什么应用程序在GoogleApiClient.connect()上被强制关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:21