final Task<DriveFolder> appFolderTask = getDriveResourceClient().getAppFolder();
final Task<DriveContents> createContentsTask = getDriveResourceClient().createContents();
Tasks.whenAll(appFolderTask, createContentsTask)
.continueWithTask(new Continuation<Void, Task<DriveFile>>() {
@Override
public Task<DriveFile> then(@NonNull Task<Void> task) throws Exception {
DriveFolder parent = appFolderTask.getResult();
DriveContents contents = createContentsTask.getResult();
OutputStream outputStream = contents.getOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream)) {
writer.write(data);
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("Demo`enter code here`")
.setMimeType("text/plain")
.setStarred(true)
.build();
return getDriveResourceClient().createFile(parent, changeSet, contents);
}
})
.addOnSuccessListener(this,
new OnSuccessListener<DriveFile>() {
@SuppressLint("StringFormatInvalid")
@Override
public void onSuccess(DriveFile driveFile) {
showMessage(getString(R.string.file_created,
driveFile.getDriveId().encodeToString()));
//finish();
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Unable to create file", e);
showMessage(getString(R.string.file_create_error));
//finish();
}
});
我已成功将文件上传到app文件夹,但没有从Drive的应用文件夹中获取任何资源。
怎么可能?
答案 0 :(得分:0)
我通过从driveResourceClient实例调用getAppFolder方法获得了我的答案
import json
a = '\ud83d\udc95'
m = json.dumps({"k": a})
print(json.loads(m)["k"]) #