Android游戏:GoogleApiClient崩溃

时间:2014-05-18 17:04:22

标签: android api client

我用Java Canvas开发了一款游戏。现在我想从谷歌添加排行榜。 首先,我必须使用谷歌帐户登录。但它一开始就崩溃了。

这是我的错误日志(对不起): ErrorLog Part #1 ErrorLog Part #2 ErrorLog Part #3 ErrorLog Part #4 ErrorLog Part #5

这是我的AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.lolxdfly.mygame"
    android:versionCode="1"
    android:versionName="0.1" >

    <uses-sdk
        android:minSdkVersion="8" 
        android:targetSdkVersion="11" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <activity
            android:label="@string/app_name"
            android:name=".MainActivity"
            android:screenOrientation="landscape" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity 
            android:name="com.google.ads.AdActivity" 
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

        <meta-data 
            android:name="com.google.android.gms.version"
            android:value="4323000" />

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

    </application>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

</manifest>

StringResource中的appid:<string name="app_id">699887223877</string>

至少这是我加载APICLient的代码:

public static GoogleApiClient gapic;


//at onCreate:
gapic = new GoogleApiClient.Builder(this, this, this).addApi(Games.API).addApi(Plus.API).addApi(AppStateManager.API).addScope(Games.SCOPE_GAMES).addScope(Plus.SCOPE_PLUS_LOGIN).addScope(AppStateManager.SCOPE_APP_STATE).build();


    @Override 
    public void onStart()
    { 
        super.onStart();
        gapic.connect(); 
    }

    @Override public void onConnected(Bundle connectionHint)
    { /*Toast.makeText(getApplicationContext(), connectionHint.toString(), Toast.LENGTH_LONG).show();*/}
    @Override public void onConnectionSuspended(int cause)
    { /*Toast.makeText(getApplicationContext(), cause, Toast.LENGTH_LONG).show();*/}
    @Override public void onConnectionFailed(ConnectionResult connectionResult)
    { Toast.makeText(getApplicationContext(), connectionResult.toString(), Toast.LENGTH_LONG).show();}

更新:它现在有效..与其他间隙初始化:

   gapic = new GoogleApiClient.Builder(this).addApi(Games.API).addOnConnectionFailedListener(this).build();

但是如果我想要更新排行榜,我现在得到java.lang.IllegalStateEsception: GoogleApiClient is not connected yet.

但是我怎么能用这段代码得到未连接的消息?

if(MainActivity.gapic.isConnected && !MainActivity.gapic.isConnecting)
   Games.Leaderboards.sumbitScoreImmediate(MainAcitivy.gapic, "HERE IS MY ID ENTERED", points);

1 个答案:

答案 0 :(得分:0)

从您的堆栈跟踪中可以看出您缺少Google Play服务。您应该检查用户是否安装了它们。如果没有,您应该允许用户安装它们。

了解他们如何处理docs上的错误(即Google Play服务不存在)。