Esempio n. 1
0
        public void Download(DriveId driveId)
        {
            /*
             * Download snippet from:
             * http://stackoverflow.com/questions/37407368/android-drive-api-download-file
             */

            Task.Run(delegate
            {
                if (DownloadStarted != null)
                {
                    DownloadStarted(null, null);
                }

                /*
                 * All "Result" variables are under Android.Gms.Drive, search for "result".
                 * Be sure to await, else it'll return cast failure
                 */

                IDriveFile file = DriveClass.DriveApi.GetFile(client, driveId);
                IDriveApiDriveContentsResult result = file.Open(client, Android.Gms.Drive.DriveFile.ModeReadOnly, null).Await().JavaCast <IDriveApiDriveContentsResult>();

                IDriveResourceMetadataResult metadataResult = file.GetMetadata(client).Await().JavaCast <IDriveResourceMetadataResult>();

                Stream stream = result.DriveContents.InputStream;

                if (DownloadComplete != null)
                {
                    string name = metadataResult.Metadata.Title;
                    DownloadComplete(null, new DownloadEventArgs {
                        Stream = stream, Name = name
                    });
                }
            });
        }