Noctis Tong
Noctis Tong

Reputation: 587

ICloudStorage.GetChildren() never return

I'm trying to access Google Drive with CloudRail using the following codes.

// Actual string value removed.
private const string GDRIVE_CLIENT_ID = "client_id";
private const string ANDROID_PACKAGE_NAME = "package_name";
private const string CLOUDRAIL_APP_KEY = "app_key";
private readonly string REDIRECT_URL = $"{ANDROID_PACKAGE_NAME}:/oauth2redirect";

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    // Set CloudRail application key.
    CloudRail.AppKey = CLOUDRAIL_APP_KEY;

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);

    try
    {
        var googleDrive = new GoogleDrive(this, GDRIVE_CLIENT_ID, "", REDIRECT_URL, "state");
        googleDrive.UseAdvancedAuthentication();
        m_Service = googleDrive;

        Action act = () =>
        {
            var list = m_Service.GetChildren(@"/");
            // The function call never return.
        };
        var thread = new Thread(new ThreadStart(act));
        thread.Start();
    }
    catch (Exception ex)
    {
    }
}

After calling into ICloudStorage.GetChildren(), my apps get redirected to login into Google account. After user has logged in to Google account and granted consent to the application, the function call never return. No exception is caught either.

What could have go wrong?

Upvotes: 1

Views: 43

Answers (1)

Noctis Tong
Noctis Tong

Reputation: 587

I got a reply from CloudRail support team and manage to solved the issue with their help.

You need to include the IntentFilter and LaunchMode to SingleTask on top of your activity. Also you need to put OnNewIntent method as shown below:

[Activity(Label = "Awesome.Android", LaunchMode = Android.Content.PM.LaunchMode.SingleTask)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault }, DataScheme = "Android_Package_Name")]
public class MainActivity : Activity
{
    protected override void OnNewIntent(Intent intent)
    {
        CloudRail.AuthenticationResponse = intent;
        base.OnNewIntent(Intent);
    }
}

The key is that the corresponding Activity class (in my case, MainActivity) has to be decorated with IntentFilter. Also, OnNewItent has to be overridden and passing the response back to CloudRail.AuthenticationResponse in the override.

I also found that android package name must be in full lower case, otherwise it won't work either.

Edit [2018.07.19]

Android package name must contain at least one period character (.), otherwise, you may encounter invalid_request - missing authority error.

Upvotes: 1

Related Questions