2015-05-06 30 views
0

我采用了android 5.0.1和编译我的应用程序API 21
我想连接与此代码Google Play服务:连接的android结果

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

但它返回连接结果码8这意味着:“发生内部错误,重试应该解决问题。”
这个错误意味着什么,我该如何解决它?

回答

0

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

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

你可以显示所有的依赖关系,以便用户可以比较吗? – JPM

+0

在我的Android Dependencies文件夹中有:appcompat_v7.jar - > META-INF ---> MANIFEST.MF 你的意思是? –