Xamarin.android ICloudStorage.GetChildren()永远不会返回

Xamarin.android ICloudStorage.GetChildren()永远不会返回,xamarin.android,google-drive-api,cloudrail,Xamarin.android,Google Drive Api,Cloudrail,我正在尝试使用以下代码通过CloudRail访问Google Drive // 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

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

// 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帐户并同意应用程序后,函数调用将不再返回。也没有发现异常


出了什么问题?

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

您需要在活动顶部包括
IntentFilter
LaunchMode
SingleTask
。 您还需要将
OnNewIntent
方法放入,如下所示:

关键是相应的
Activity
类(在我的例子中,
MainActivity
)必须用
IntentFilter
修饰。此外,
onnewient
必须被覆盖,并将响应传递回覆盖中的
CloudRail.AuthenticationResponse

我还发现android软件包名称必须是小写的,否则它也不能工作

编辑[2018.07.19]

Android软件包名称必须至少包含一个句点字符(.),否则,您可能会遇到无效的_请求-缺少权限错误

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