Skip to content Skip to sidebar Skip to footer

Xamarin: Unsure What To Cast Using Drivefile.open

I tried to lookup the documentation about DriveFile.Open for Xamarin but still can't find the class to cast the return statement from the code below var pendingResult = driveFile.O

Solution 1:

Non-Async way (using OnResult callback)

driveFile.Open(_googleApiClient, DriveFile.ModeReadOnly, null).SetResultCallback(this);

Will call onResult and there you can cast the result:

void IResultCallback.OnResult(Java.Lang.Object result)
{
    var contentResults = (result).JavaCast<IDriveApiDriveContentsResult>();
    var driveContent = contentResults.DriveContents;
    D.WriteLine(driveContent.DriveId);

}

Async way:

var driveContentResult = driveFile.OpenAsync(_googleApiClient, DriveFile.ModeReadOnly, null).ContinueWith((resultTask) =>
{
    var driveContentResults = resultTask.Result;
    var driveContent = driveContentResults.DriveContents;
    D.WriteLine(driveContent.DriveId);
});

Solution 2:

You should probably make your own DrivecontentsResult and implement IDriveApiDriveContentsResult interface and use that concrete class. It is available in Android.Gms.Drive.IDriveApiDriveContentsResult

Post a Comment for "Xamarin: Unsure What To Cast Using Drivefile.open"