Victor Chelaru
Victor Chelaru

Reputation: 4847

Why does GoogleApiClient.Build.EnableAutoManage softlock my application?

Summary

I have a Xamarin application which creates a GoogleApiClient and calls EnableAutoManage. When my app runs, I am asked which user account to use, and then the app hangs on a blank popup page with a Google-themed spinner. Why is this happening?

Details

I have been following this video which shows how to set up an application's to read Google Fit data. Notice the timestamp - this is where the code is presented.

https://youtu.be/j_zsNxMI6jI?t=2172

I have followed the examples here, and have narrowed the problem to this piece of code:

// In my MainActivity's OnCreate:
try
{
    int defaultClientId = 0;
    googleApiClient = new GoogleApiClient.Builder(this)
        .AddApi(FitnessClass.HISTORY_API)
        .AddApi(FitnessClass.RECORDING_API)
        .AddScope(FitnessClass.ScopeActivityRead)
        .EnableAutoManage(this, defaultClientId, 
        result => 
        {
            int m = 3; // Breakpoint here is never hit
        })
        .Build();
}
catch (Exception e)
{
    int m = 3; // Breakpoint here is never hit either
}

If I run my app (tried on both emulator and physical hardware), I am first asked which account to use.

Account Selection

After selecting the account, another popup appears with a Google-themed (changing between red, yellow, green, and blue) spinner at the top. The popup stays on screen and the spinner animates indefinitely.

enter image description here

As noted in the code above, no exceptions are raised, and no result is returned in the EnableAutoManage delegate. Why is this happening?

Update 1

If I remove the following line, the app no longer shows a spinner indefinitely:

.AddScope(FitnessClass.ScopeActivityRead)

The addition of this line of code seems to be the cause of the popup with the spinner.

Update 2

I thought I'd try the "new" approach of using GoogleApi rather than GoogleApiClient as explained here:

https://android-developers.googleblog.com/2017/11/moving-past-googleapiclient_21.html

Unfortunately, there seem to be no Xamarin bindings for this yet:

Xamarin Android: Cannot resolve GoogleSignIn and GoogleSignInClient

Upvotes: 1

Views: 112

Answers (1)

Victor Chelaru
Victor Chelaru

Reputation: 4847

The reason this happened is because my google account hadn't yet been added as a test user. One might expect that Google would provide some kind of useful feedback through a popup, but instead it provided an empty page.

To solve this problem:

  1. Go to https://console.cloud.google.com/apis/dashboard
  2. Click on OAuth consent screen consent screen
  3. Scroll down to the Test Users section Test Users
  4. Enter the email addresses of the test users you would like to use testing your app (such as your own personal gmail)

Now the app should properly display a confirmation page.

Upvotes: 1

Related Questions