Error implementing GoogleApiClient Builder for Android development

后端 未结 5 604
走了就别回头了
走了就别回头了 2020-12-05 07:06

I am following Google\'s documentation to implement Google+ Sign In feature into an app.

https://developers.google.com/+/mobile/android/getting-started

I fol

相关标签:
5条回答
  • 2020-12-05 07:10

    click alt enter and force android studio to implement:

    GoogleApiClient.ConnectionCallbacks,

    GoogleApiClient.OnConnectionFailedListener

    0 讨论(0)
  • 2020-12-05 07:12

    I see in their documentation where they clearly instruct you to include this import:

    import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
    

    However, the error being thrown is expecting a different class than GooglePlayServicesClient.ConnectionCallbacks, it's asking for GoogleApiClient.ConnectionCallbacks. Try changing your implements to use the more-qualified class name. That looks to be the only possible thing throwing the code for a loop and without the explicit qualified classname, it will default to the directly imported class name.

    It's always tougher when you have to question the manual.

    Edit: I mean a change like this:

    public class MainActivity 
        extends ActionBarActivity 
        implements GoogleApiClient.ConnectionCallbacks,
                   GoogleApiClient.OnConnectionFailedListener {
    
    0 讨论(0)
  • 2020-12-05 07:14
       implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,OnMapReadyCallback
    

    to the Activity

    0 讨论(0)
  • 2020-12-05 07:19

    turns out they (google) don't follow much of the guide themselves. Use their Google Drive Android Quickstart as a reference, which they actually do mention at the top of the tutorial, but they give it the misleading name "Android Quickstart" even though it is specific to Google Drive

    The note at the top of the guide: The note at the top of the guide

    0 讨论(0)
  • 2020-12-05 07:28

    I too faced the same problem, i resolved by doing the following things.

    import the right ConnectionCallbacks.

    here is my code:

    import android.content.Context;
    import android.os.Bundle;
    
    import com.google.android.gms.common.ConnectionResult;
    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.drive.Drive;
    
    public class GplusLogin implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {
    GoogleApiClient mGoogleApiClient;
    GplusLogin(Context context){
    
        mGoogleApiClient = new GoogleApiClient.Builder(context)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks((GoogleApiClient.ConnectionCallbacks) context)
                .addOnConnectionFailedListener(this)
                .build();
    }
    
    @Override
    public void onConnected(Bundle bundle) {
    
    }
    
    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
    
    }
    
    @Override
    public void onConnectionSuspended(int i) {
    
    }
    }
    
    0 讨论(0)
提交回复
热议问题