Код: Выделить всё
public Object loadInBackground() {
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(mycontext);
assert account != null;
mDriveServiceHelper = new DriveServiceHelper(getGoogleDriveService(mycontext, account, "E Aid"));
mDriveServiceHelper.searchFile(file.getName(), "*/*").addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(List googleDriveFileHolders) {
Gson gson = new Gson();
try {
JSONArray jsonArray = new JSONArray(gson.toJson(googleDriveFileHolders));
// Log.i(TAG, jsonArray.toString());
if (jsonArray.length() != 0) {
HyperLog.i(TAG, file.getName() + " found at GD");
//Duplicate File, Delete at Local Level
} else {
HyperLog.i(TAG, "Check " + file.getName() + " Not Found ");
mDriveServiceHelper.uploadFile(file, "*/*", folderId, mycontext);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
return null;
}
Код: Выделить всё
public Task uploadFile(final java.io.File localFile, final String mimeType, @Nullable final String folderId, final Context context) {
return Tasks.call(mExecutor, new Callable() {
@Override
public GoogleDriveFileHolder call() throws Exception {
// Retrieve the metadata as a File object.
Log.i(TAG, "Special Check Inside Upload Function");
List root;
if (folderId == null) {
root = Collections.singletonList("root");
} else {
root = Collections.singletonList(folderId);
}
File metadata = new File()
.setParents(root)
.setMimeType(mimeType)
.setName(localFile.getName());
FileContent fileContent = new FileContent(mimeType, localFile);
File fileMeta = mDriveService.files().create(metadata, fileContent).execute();
GoogleDriveFileHolder googleDriveFileHolder = new GoogleDriveFileHolder();
googleDriveFileHolder.setId(fileMeta.getId());
googleDriveFileHolder.setName(fileMeta.getName());
if (googleDriveFileHolder.getId() != null) {
Log.i(TAG, localFile.getAbsolutePath() + " has uploaded Successfully ");
}
return googleDriveFileHolder;
}
});
}
Может кто-нибудь помочь исправить это, чего не хватает которые можно добавить сюда.
Подробнее здесь: https://stackoverflow.com/questions/781 ... ogle-drive
Мобильная версия