我正在處理某些用戶數據備份到Google驅動器的應用程序,並在稍後時間恢復它們。無法上傳或下載Google Drive Android SDK中的進度
問題是,創建和恢復的文件沒有問題,除了我看不到任何進展,如果我上傳一個大文件,它一直在後臺執行該操作,並且無法通知用戶存在一些操作發生在後臺。
這裏是從方法的一個片段,我使用
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
}
});
}
});
的問題是,如果我'上傳3個文件,該 Log.d(TAG,Log.d(TAG, "Created a file with content: " + result.getDriveFile().getDriveId());
非常迅速對方後稱,並與實際文件上傳保存在背景中。
那麼誰能告訴我如何在後臺獲取上傳文件的真實狀態?