在Android云端硬盘上上传文件,然后在Google云端硬盘上上传文件,没有在云端硬盘上上传文件。 Tem alguma forma de pular essa tela?
private Task<Void> createFileIntentSender(DriveContents driveContents) {
final String inFileName = activity.getDatabasePath(DATABASE_NAME).toString();
try {
File dbFile = new File(inFileName);
FileInputStream fis = new FileInputStream(dbFile);
OutputStream outputStream = driveContents.getOutputStream();
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setTitle("appchamada_bkp2.db")
.setMimeType("application/db")
.build();
CreateFileActivityOptions createFileActivityOptions =
new CreateFileActivityOptions.Builder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(driveContents)
.build();
return mDriveClient
.newCreateFileActivityIntentSender(createFileActivityOptions)
.continueWith(
task -> {
createFileIntentSender(driveContents);
//activity.startIntentSenderForResult(task.getResult(), REQUEST_CODE_CREATION, null, 0, 0, 0);
return null;
});
}
答案 0 :(得分:0)
一种可溶的或可替代的产品:
final Task<DriveFolder> rootFolderTask = mDriveResourceClient.getRootFolder();
final Task<DriveContents> createContentsTask = mDriveResourceClient.createContents();
Tasks.whenAll(rootFolderTask, createContentsTask)
.continueWithTask(task -> {
DriveFolder parent = rootFolderTask.getResult();
DriveContents contents = createContentsTask.getResult();
try {
File dbFile = new File(inFileName);
FileInputStream fis = new FileInputStream(dbFile);
OutputStream outputStream = contents.getOutputStream();
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("appchamada_bkp.db")
.setMimeType("application/db")
.setStarred(true)
.build();
return mDriveResourceClient.createFile(parent, changeSet, contents);
})
.addOnSuccessListener(activity, new OnSuccessListener<DriveFile>() {
@Override
public void onSuccess(DriveFile driveFile) {
Toast.makeText(activity, "Backup realizado", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(activity, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(activity, "Erro ao fazer backup", Toast.LENGTH_SHORT).show();
}
});
return null;