OnResult从未在DriveApi.NewDriveContent之后调用

时间:2018-03-07 08:49:23

标签: android google-client-login

我试图通过Android在谷歌驱动器上创建一个文件,我成功登录谷歌但是当我尝试创建驱动器内容时,我没有收到OnResult。 这是我的代码:

public class GoogleDrive: Java.Lang.Object, IResultCallback
{
    GoogleApiClient GAClient;

    public GoogleDrive(Android.Content.Res.Resources res,GoogleApiClient gac)
    {
        GAClient=gac;

        DriveClass.DriveApi.NewDriveContents(GAClient).SetResultCallback(this);
    }

    void IResultCallback.OnResult(Java.Lang.Object result)
    {
        var contentResults = (result).JavaCast<IDriveApiDriveContentsResult>();
        Statuses a=contentResults.Status;
        if (!contentResults.Status.IsSuccess) // handle the error
            return;

        Task.Run(() =>
        {
            var writer = new OutputStreamWriter(contentResults.DriveContents.OutputStream);
            writer.Write("Stack Overflow");
            writer.Close();

            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                   .SetTitle("test.txt")
                   .SetMimeType("text/plain")
                   .Build();

            DriveClass.DriveApi
                      .GetRootFolder(GAClient)
                      .CreateFile(GAClient, changeSet, contentResults.DriveContents);
        });
    }

    public IDriveContents DriveContents
    {
        get
        {
            throw new NotImplementedException();
        }
    }

    public Statuses Status
    {
        get
        {
            throw new NotImplementedException();
        }
    }

    public void Dispose()
    {

    }

DriveClass.DriveApi.NewDriveContents(GAClient).SetResultCallback(this);后没有任何事情发生,程序永远不会进入OnResult。是否有OnFailed方法可以帮助我?

0 个答案:

没有答案