Drive Kit allows your app to perform batch operations using an API, including:
private Drive buildDrive() {
Drive service = new Drive.Builder(CredentialManager.getInstance().getCredential(), context).build();
return service;
} /**
* Create a batch of callbacks.
*/
JsonBatchCallback<File> callback = new JsonBatchCallback<File>() {
@Override
public void onFailure(JsonError e, HttpHeaders responseHeaders) throws IOException {
Logger.i(TAG, "callback error: " + e.toString());
}
@Override
public void onSuccess(File file, HttpHeaders responseHeaders) throws IOException {
Logger.i(TAG, "callback successful: " + file.toString());
}
};
/**
* Create a batch of folders.
*/
private void batchCreateDirectory() {
Drive drive = buildDrive();
BatchRequest batch = drive.batch();
try {
for (int i = 0; i < 2; i++) {
Map<String, String> appProperties = new HashMap<>();
appProperties.put("appProperties", "property");
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
String dirName = formatter.format(new Date()) + "_" + i;
Logger.i(TAG, "executeFilesCreate: " + dirName);
File file = new File();
file.setFileName(dirName)
.setAppSettings(appProperties)
.setMimeType("application/vnd.huawei-apps.folder");
Drive.Files.Create create = drive.files().create(file);
create.queue(batch, callback);
}
batch.execute();
} catch (Exception e) {
Logger.e(TAG, "batchCreateDirectory error: " + e.toString());
}
}