连接结果 android

connection Result android

我正在使用 android 5.0.1 并使用 API 21.
编译我的应用程序 我想使用以下代码连接到 google 播放服务:

package com.example.getlocation2;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.location.LocationServices;


public class MainActivity extends ActionBarActivity implements
ConnectionCallbacks, OnConnectionFailedListener{

public GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String tag="test";
    Log.i(tag, "just for test");
    //buildGoogleApiClient();
    mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Drive.API)
    .addScope(Drive.SCOPE_FILE)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();
}
/**
 * Builds a GoogleApiClient. Uses the addApi() method to request the LocationServices API.
 */
/*protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    mGoogleApiClient.connect();
}*/

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}
 @Override
    protected void onStop() {
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

 @Override
    public void onConnectionFailed(ConnectionResult result) {
        // Refer to the java doc for ConnectionResult to see what error
        //codes might be returned in
        // onConnectionFailed.
     String TAG="Fword";
     Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
    }

/**
 * Runs when a GoogleApiClient object successfully connects.
 */
@Override
public void onConnected(Bundle connectionHint) {
    // Provides a simple way of getting a device's location and is well suited for
    // applications that do not require a fine-grained location and that do not need location
    // updates. Gets the best and most recent location currently available, which may be null
    // in rare cases when a location is not available.
    String TAG="GoodWord";
    Log.i(TAG, "Connectioned");
}

@Override
public void onConnectionSuspended(int cause) {
    // The connection to Google Play services was lost for some reason. We call connect() to
    // attempt to re-establish the connection.
    /*String TAG="Sword";
    Log.i(TAG, "Connection suspended");
    mGoogleApiClient.connect();*/
}
}

但它 returns 连接结果代码 8 表示:"internal error occurred. Retrying should resolve the problem."
这个错误是什么意思,我该如何解决?

将此添加到 gradle 构建文件的依赖项部分。

 compile 'com.google.android.gms:play-services:7.0.0'