ICloudStorage.GetChildren() 从不 return

ICloudStorage.GetChildren() never return

我正在尝试使用以下代码访问 Google Drive with CloudRail。

// 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)
    {
    }
}

调用 ICloudStorage.GetChildren() 后,我的应用程序被重定向到登录 Google 帐户。在用户登录到 Google 帐户并同意该应用程序后,函数调用永远不会 return。也没有发现异常。

哪里出了问题?

我收到了 CloudRail 支持团队的回复,并在他们的帮助下设法解决了这个问题。

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);
    }
}

关键是对应的Activityclass(我这里是MainActivity)要用IntentFilter修饰。此外,必须覆盖 OnNewItent 并将响应传回覆盖中的 CloudRail.AuthenticationResponse

我还发现android包名必须全小写,否则也不行

编辑 [2018.07.19]

Android包名必须至少包含一个句号(.),否则可能会遇到invalid_request - missing authority错误。