I am working on application where i take a backup of some user's data to Google drive and in a later time i restore them.
The problem is that the files created and restored with no problems except that i can't see any progress, if i am uploading a large file it keep doing that in the background and can't notify the user that there is some operation happening in the background.
here is a snippet from the method i am using
Drive.DriveApi.newDriveContents(client)
.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(@NonNull DriveApi.DriveContentsResult driveContentsResult) {
final DriveContents driveContents = driveContentsResult.getDriveContents();
File file = new File(filesToUpload.get(0).getURI());
// write content to DriveContents
OutputStream outputStream = driveContentsResult.getDriveContents().getOutputStream();
try {
outputStream.write(FileManagerUtils.getBytes(file));
} catch (IOException e) {
e.printStackTrace();
NotificationManger.dismissUploadingNotification();
NotificationManger.showSucessNotification(getApplicationContext(), R.string.notification_uploading_success);
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(obj.getFileName())
.build();
DriveId folderID = null;
// create a file on root folder
Drive.DriveApi.getFolder(client, folderID)
.createFile(client, changeSet, driveContents)
.setResultCallback(new ResultCallbacks<DriveFolder.DriveFileResult>() {
@Override
public void onSuccess(@NonNull DriveFolder.DriveFileResult result) {
if (!result.getStatus().isSuccess()) {
Log.d(TAG, "Error while trying to create the file");
return;
}
Log.d(TAG, "Created a file with content: " + result.getDriveFile().getDriveId());
if (filesToUpload.size() > 0) {
filesToUpload.remove(0);
backup();
}
}
@Override
public void onFailure(@NonNull Status status) {
// show error
}
});
}
});
The problem is that if i'am uploading 3 files, the
Log.d(TAG,Log.d(TAG, "Created a file with content: " + result.getDriveFile().getDriveId());
is called very quickly after each others, and the actual files keep uploading in the background.
So can anyone tell me how to get real status of the uploading files in the background?