GoogleApiClient.connect()导致强制关闭

时间:2015-08-11 07:25:11

标签: android google-api-client google-signin

首先我发现这个问题之前已被问过2次,但他们都没有明确答案,也没有解决问题的答案。

这是我第一次实施Google Sign-In。但是,GoogleApiClient.connect();会导致申请人关闭。我不知道为什么。任何的想法?感谢

代码:

package com.example.fujitsu.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
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.example.games.basegameutils.BaseGameUtils;

public class MainActivity extends Activity implements 
        View.OnClickListener,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

private GoogleApiClient mGoogleApiClient;
private static int RC_SIGN_IN = 9001;

private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInFlow = true;
private boolean mSignInClicked = false;
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false; 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create the Google Api Client with access to the Play Games services
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);

}

@Override
protected void onStart() {
    super.onStart();
    if (!mInSignInFlow && !mExplicitSignOut) {
        // auto sign in
        mGoogleApiClient.connect();
    }
}

@Override
protected void onStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
}

@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;
        // user explicitly signed out, so turn off auto sign in
        mExplicitSignOut = true;
        if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
            Games.signOut(mGoogleApiClient);
            mGoogleApiClient.disconnect();
        }

        // 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);
    }
}

@Override
public void onConnected(Bundle connectionHint) {
    // show sign-out button, hide the sign-in button
    findViewById(R.id.sign_in_button).setVisibility(View.GONE);
    findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    if (mResolvingConnectionFailure) {
        // already resolving
        return;
    }

    // if the sign-in button was clicked or if auto sign-in is enabled,
    // launch the sign-in flow
    if (mSignInClicked || mAutoStartSignInFlow) {
        mAutoStartSignInFlow = false;
        mSignInClicked = false;
        mResolvingConnectionFailure = true;

        if (!BaseGameUtils.resolveConnectionFailure(this,
                mGoogleApiClient, connectionResult,
                RC_SIGN_IN, "There was an issue with sign-in, please try again later.")) {
            mResolvingConnectionFailure = false;
        }
    }

}
protected void onActivityResult(int requestCode, int resultCode,
                                Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        mSignInClicked = false;
        mResolvingConnectionFailure = false;
        if (resultCode == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            BaseGameUtils.showActivityResultError(this,
                    requestCode, resultCode, R.string.signin_failure);
        }
    }
}


@Override
public void onConnectionSuspended(int i) {
    // Attempt to reconnect
    mGoogleApiClient.connect();
}
}

Android清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fujitsu.myapplication" >

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

logcat的:

libcore.io.ErrnoException: close failed: EBADF (Bad file number)
            at libcore.io.Posix.close(Native Method)
            at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
            at com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:221)
            at com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
            at com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
            at com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:713)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:649)
            at dalvik.system.NativeStart.main(Native Method)
08-11 14:08:46.883  24869-24881/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=9: interp stack at 0x5f551000
08-11 14:08:46.883  24869-24881/com.example.fujitsu.myapplication D/dalvikvm﹕ init ref table
08-11 14:08:46.883  24869-24881/com.example.fujitsu.myapplication D/dalvikvm﹕ init mutex
08-11 14:08:46.884  24869-24882/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=10: interp stack at 0x5f66f000
08-11 14:08:46.884  24869-24882/com.example.fujitsu.myapplication D/dalvikvm﹕ init ref table
08-11 14:08:46.884  24869-24882/com.example.fujitsu.myapplication D/dalvikvm﹕ init mutex
08-11 14:08:46.929  24869-24869/com.example.fujitsu.myapplication V/SettingsProviderInterface﹕ invalidate [system]: current 59 != cached 0
08-11 14:08:46.931  24869-24869/com.example.fujitsu.myapplication D/ActivityThread﹕ hoder:android.app.IActivityManager$ContentProviderHolder@4266d840,provider,holder.Provider:android.content.ContentProviderProxy@4266dfb8
08-11 14:08:46.934  24869-24869/com.example.fujitsu.myapplication D/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
08-11 14:08:46.960  24869-24869/com.example.fujitsu.myapplication D/Proxy﹕ setHttpRequestCheckHandler
08-11 14:08:46.961  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ open_cached_dex_file : /data/app/com.example.fujitsu.myapplication-1.apk /data/dalvik-cache/data@app@com.example.fujitsu.myapplication-1.apk@classes.dex
08-11 14:08:46.970  24869-24869/com.example.fujitsu.myapplication D/ActivityThread﹕ BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{4266ace8 com.example.fujitsu.myapplication}}
08-11 14:08:46.971  24869-24869/com.example.fujitsu.myapplication V/ActivityThread﹕ Handling launch of ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}}
08-11 14:08:47.021  24869-24869/com.example.fujitsu.myapplication V/ActivityThread﹕ ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}}: app=android.app.Application@42672248, appName=com.example.fujitsu.myapplication, pkg=com.example.fujitsu.myapplication, comp={com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}, dir=/data/app/com.example.fujitsu.myapplication-1.apk
08-11 14:08:47.025  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ create interp thread : stack size=128KB
08-11 14:08:47.025  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ create new thread
08-11 14:08:47.025  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ new thread created
08-11 14:08:47.025  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ update thread list
08-11 14:08:47.025  24869-24886/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=11: interp stack at 0x5fd9e000
08-11 14:08:47.025  24869-24886/com.example.fujitsu.myapplication D/dalvikvm﹕ init ref table
08-11 14:08:47.025  24869-24886/com.example.fujitsu.myapplication D/dalvikvm﹕ init mutex
08-11 14:08:47.025  24869-24886/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=11: created from interp
08-11 14:08:47.025  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ start new thread
08-11 14:08:47.025  24869-24886/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=11: notify debugger
08-11 14:08:47.025  24869-24886/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=11 (LaunchIconThemeResource): calling run()
08-11 14:08:47.033  24869-24869/com.example.fujitsu.myapplication D/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
08-11 14:08:47.062  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.example.fujitsu.myapplication asetfile:null
08-11 14:08:47.063  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.example.fujitsu.myapplication asetfile:null
08-11 14:08:47.128  24869-24869/com.example.fujitsu.myapplication I/dalvikvm﹕ Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
08-11 14:08:47.128  24869-24869/com.example.fujitsu.myapplication W/dalvikvm﹕ VFY: unable to resolve virtual method 245: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
08-11 14:08:47.128  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x00c2
08-11 14:08:47.130  24869-24869/com.example.fujitsu.myapplication I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
08-11 14:08:47.130  24869-24869/com.example.fujitsu.myapplication W/dalvikvm﹕ VFY: unable to resolve virtual method 535: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
08-11 14:08:47.130  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000b
08-11 14:08:47.131  24869-24869/com.example.fujitsu.myapplication D/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
08-11 14:08:47.193  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ open_cached_dex_file : /system/framework/com.android.location.provider.jar /data/dalvik-cache/system@framework@com.android.location.provider.jar@classes.dex
08-11 14:08:47.194  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ open_cached_dex_file : /system/framework/com.android.media.remotedisplay.jar /data/dalvik-cache/system@framework@com.android.media.remotedisplay.jar@classes.dex
08-11 14:08:47.197  24869-24869/com.example.fujitsu.myapplication D/dalvikvm﹕ open_cached_dex_file : /data/app/com.google.android.gms-1.apk /data/dalvik-cache/data@app@com.google.android.gms-1.apk@classes.dex
08-11 14:08:47.227  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.example.fujitsu.myapplication asetfile:null
08-11 14:08:47.243  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.google.android.gms asetfile:null
08-11 14:08:47.253  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.google.android.gms asetfile:null
08-11 14:08:47.259  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.google.android.gms asetfile:null
08-11 14:08:47.262  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.google.android.gms asetfile:null
08-11 14:08:47.264  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.google.android.gms asetfile:null
08-11 14:08:47.268  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.google.android.gms asetfile:null
08-11 14:08:47.281  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.example.fujitsu.myapplication asetfile:null
08-11 14:08:47.316  24869-24869/com.example.fujitsu.myapplication W/PopupManager﹕ You have not specified a View to use as content view for popups. Falling back to the Activity content view. Note that this may not work as expected in multi-screen environments
08-11 14:08:47.317  24869-24869/com.example.fujitsu.myapplication V/ActivityThread﹕ Performing resume of ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}} finished=false
08-11 14:08:47.317  24869-24869/com.example.fujitsu.myapplication D/ActivityThread﹕ ACT-AM_ON_RESUME_CALLED ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}}
08-11 14:08:47.317  24869-24869/com.example.fujitsu.myapplication V/ActivityThread﹕ Resume ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}} started activity: false, hideForNow: false, finished: false
08-11 14:08:47.317  24869-24869/com.example.fujitsu.myapplication V/PhoneWindow﹕ DecorView setVisiblity: visibility = 4 ,Parent =null, this =com.android.internal.policy.impl.PhoneWindow$DecorView{4267a318 I.E..... R.....ID 0,0-0,0}
08-11 14:08:47.326  24869-24869/com.example.fujitsu.myapplication V/ActivityThread﹕ Resuming ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}} with isForward=true
08-11 14:08:47.326  24869-24869/com.example.fujitsu.myapplication V/PhoneWindow﹕ DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{4271dc00 com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{4267a318 V.E..... R.....ID 0,0-0,0}
08-11 14:08:47.326  24869-24869/com.example.fujitsu.myapplication V/ActivityThread﹕ Scheduling idle handler for ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}}
08-11 14:08:47.327  24869-24869/com.example.fujitsu.myapplication D/ActivityThread﹕ ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{4266c7a8 token=android.os.BinderProxy@4266bd30 {com.example.fujitsu.myapplication/com.example.fujitsu.myapplication.MainActivity}}
08-11 14:08:47.338  24869-24869/com.example.fujitsu.myapplication D/jiayh2﹕ FontThemeManager createThemeFont typefacetype=2, curfontpath=/system/fonts/DroidSansFallback.ttf
08-11 14:08:47.404  24869-24869/com.example.fujitsu.myapplication D/GraphicBuffer﹕ create handle(0x622ea9b0) (w:736, h:1280, f:1)
08-11 14:08:47.407  24869-24869/com.example.fujitsu.myapplication D/OpenGLRenderer﹕ Enabling debug mode 0
08-11 14:08:47.408  24869-24869/com.example.fujitsu.myapplication D/GraphicBuffer﹕ create handle(0x626ad790) (w:1984, h:1472, f:1)
08-11 14:08:47.417  24869-24869/com.example.fujitsu.myapplication D/OpenGLRenderer﹕ setViewport 720x1280 <0x622eaad8>
08-11 14:08:47.418  24869-24869/com.example.fujitsu.myapplication V/InputMethodManager﹕ onWindowFocus: null softInputMode=288 first=true flags=#1810100
08-11 14:08:47.418  24869-24869/com.example.fujitsu.myapplication V/InputMethodManager﹕ START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{4267a318 V.E..... R.....ID 0,0-720,1280} ic=null tba=android.view.inputmethod.EditorInfo@4272b720 controlFlags=#104
08-11 14:08:47.423  24869-24889/com.example.fujitsu.myapplication D/dalvikvm﹕ threadid=12: interp stack at 0x63306000
08-11 14:08:47.423  24869-24889/com.example.fujitsu.myapplication D/dalvikvm﹕ init ref table
08-11 14:08:47.423  24869-24889/com.example.fujitsu.myapplication D/dalvikvm﹕ init mutex
08-11 14:08:49.603  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch down dispatch to android.widget.RelativeLayout{4267ffc0 V.E..... ......I. 0,0-720,1230}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=150.79057, y[0]=143.84856, Xw[0]=32.0, Yw[0]=32.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35442457, downTime=35442457, deviceId=3, source=0x1002 }
08-11 14:08:49.603  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch down dispatch to android.widget.FrameLayout{4267ef40 V.ED.... ......I. 0,50-720,1280 #1020002 android:id/content}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=150.79057, y[0]=143.84856, Xw[0]=32.0, Yw[0]=32.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35442457, downTime=35442457, deviceId=3, source=0x1002 }
08-11 14:08:49.604  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch down dispatch to android.widget.LinearLayout{4267b400 V.E..... ......I. 0,0-720,1280}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=150.79057, y[0]=193.84856, Xw[0]=32.0, Yw[0]=32.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35442457, downTime=35442457, deviceId=3, source=0x1002 }
08-11 14:08:49.604  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch down dispatch to com.android.internal.policy.impl.PhoneWindow$DecorView{4267a318 V.E..... R.....I. 0,0-720,1280}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=150.79057, y[0]=193.84856, Xw[0]=32.0, Yw[0]=32.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35442457, downTime=35442457, deviceId=3, source=0x1002 }
08-11 14:08:49.715  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch up dispatch to com.android.internal.policy.impl.PhoneWindow$DecorView{4267a318 V.E..... R.....I. 0,0-720,1280}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=149.79196, y[0]=193.84856, Xw[0]=33.0, Yw[0]=33.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35442570, downTime=35442457, deviceId=3, source=0x1002 }
08-11 14:08:56.147  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch down dispatch to com.google.android.gms.common.internal.cq{42690b00 VFED..C. ........ 0,0-216,96}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=133.76978, y[0]=50.89618, Xw[0]=64.0, Yw[0]=64.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35448999, downTime=35448999, deviceId=3, source=0x1002 }
08-11 14:08:56.168  24869-24869/com.example.fujitsu.myapplication D/GraphicBuffer﹕ create handle(0x633c3b28) (w:736, h:1280, f:1)
08-11 14:08:56.317  24869-24869/com.example.fujitsu.myapplication I/View﹕ Touch up dispatch to com.google.android.gms.common.internal.cq{42690b00 VFED..C. ...P.... 0,0-216,96}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=132.77115, y[0]=50.89618, Xw[0]=49.0, Yw[0]=49.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=35449172, downTime=35448999, deviceId=3, source=0x1002 }
08-11 14:08:56.337  24869-24869/com.example.fujitsu.myapplication D/GraphicBuffer﹕ create handle(0x6332fc28) (w:736, h:1280, f:1)
08-11 14:08:56.452  24869-24869/com.example.fujitsu.myapplication D/AndroidRuntime﹕ Shutting down VM
08-11 14:08:56.452  24869-24869/com.example.fujitsu.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4190cc98)
08-11 14:08:56.452  24869-24869/com.example.fujitsu.myapplication W/dalvikvm﹕ threadid=1: uncaught exception occurred
08-11 14:08:56.452  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
08-11 14:08:56.461  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at com.google.android.gms.common.internal.zzi$zza.zzc(Unknown Source)
08-11 14:08:56.462  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at com.google.android.gms.common.internal.zzi$zza.zzr(Unknown Source)
08-11 14:08:56.462  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at com.google.android.gms.common.internal.zzi$zzc.zznQ(Unknown Source)
08-11 14:08:56.462  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at com.google.android.gms.common.internal.zzi$zzb.handleMessage(Unknown Source)
08-11 14:08:56.462  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:110)
08-11 14:08:56.463  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at android.os.Looper.loop(Looper.java:193)
08-11 14:08:56.463  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5395)
08-11 14:08:56.463  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
08-11 14:08:56.463  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
08-11 14:08:56.463  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
08-11 14:08:56.464  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)
08-11 14:08:56.464  24869-24869/com.example.fujitsu.myapplication W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
08-11 14:08:56.464  24869-24869/com.example.fujitsu.myapplication W/dalvikvm﹕ threadid=1: calling UncaughtExceptionHandler
08-11 14:08:56.465  24869-24869/com.example.fujitsu.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.fujitsu.myapplication, PID: 24869
    java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
            at com.google.android.gms.common.internal.zzi$zza.zzc(Unknown Source)
            at com.google.android.gms.common.internal.zzi$zza.zzr(Unknown Source)
            at com.google.android.gms.common.internal.zzi$zzc.zznQ(Unknown Source)
            at com.google.android.gms.common.internal.zzi$zzb.handleMessage(Unknown Source)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:5395)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

您可以按照以下步骤解决此问题, 第1步:首先在开发者控制台中启用google + API。从开发者控制台创建新的客户端ID。

第2步:将Google Play服务添加到我们的项目中。

步骤3:在清单中声明权限。

第4步:将Google API客户端初始化为您的应用程序,

  

首先通过onResume()

中的GoogleApiClient来查看Google Play服务的可用性      

在设备上提供播放服务后,请通过调用buildGoogleApiClient()方法构建mGoogleApiClient.connect()

     

通过onStart()方法调用onConnectionFailed()连接到google API客户端。通过调用此方式,系统会根据连接状态触发onConnected()onConnectionSuspended()findViewById(R.id.sign_in_button).setVisibility(View.GONE); findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);

     

Google API成功连接后,   //显示注销按钮,隐藏登录按钮

onConnected()
应该在{{1}}方法中调用

如果您遇到困难,请遵循 https://developers.google.com/+/mobile/android/getting-started