Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble enabling GoogleApiClient in AppCompatActivity

Trying to follow basic setup as per Google's guides:

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
        .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
        .build();

The second "this" for the OnConnectionFailedListener fails

Wrong 2nd argument type.

Found: '... .HomeScreen', required: 'com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener' less...

enableAutoManage (FragmentActivity, com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener) in Builder cannot be applied to (HomeScreen, ... .HomeScreen)

So I tested this by changing the class extend from AppCompatActivity to FragmentActivity and it worked fine.

I'm not sure how to implement a listener to satisfy manually, and since AppCompatActivity extends FragmentActivity, I'm very confused as to what is going on in this case to debug it.

Further, the class has AppCompatActivity dependencies, so I'm not sure how to proceed in setting up the API.

This is follow on work to setting up the FacebookSDK, which I got working, so I was kind of hoping they had a similarly functioning "button", and that it may work in a similar manner, but the equivalent SDK initialization seems to be hiccuping at this stage.

Any direction would be welcomed.

Also, for clarification, I only need to be able to authenticate with Google, where as tagging this post with the API suggests that it is for Google Play Services, which is beyond the scope of what I require, so if I can just axe this portion, that'd be fine.

like image 347
Captain Prinny Avatar asked Feb 10 '16 03:02

Captain Prinny


1 Answers

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .enableAutoManage(this ,(OnConnectionFailedListener) this )
    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
    .build();

Simply adding a cast worked for me

like image 120
Pomagranite Avatar answered Oct 03 '22 01:10

Pomagranite