1
드라이브에 여러 파일을 업로드 할 수 있지만 작업 완료 시점을 알 수 없습니다. 결과 콜백은 나에게 잘 보이지만 인터넷 연결을 닫으면 작업이 중단됩니다.Android - Google 드라이브 Api : 업로드 작업이 완료되면 어떻게 알 수 있습니까?
내가 모든 파일이 이미 클라우드에 업로드되어 있는지 확인 때 알고 싶은void createFile(DriveFolder pFldr, final String titl, final String mime, final File file) {
DriveId dId = null;
setProgressing(true);
if (mGoogleApiClient != null && mGoogleApiClient.isConnected() && titl != null && mime != null && file != null) try {
final DriveFolder parent = pFldr != null ? pFldr : Drive.DriveApi.getRootFolder(mGoogleApiClient);
Drive.DriveApi.newDriveContents(getGoogleApiClient()).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
DriveContents cont = driveContentsResult != null && driveContentsResult.getStatus().isSuccess() ?
driveContentsResult.getDriveContents() : null;
if (cont != null) try {
OutputStream oos = cont.getOutputStream();
if (oos != null) try {
InputStream is = new FileInputStream(file);
byte[] buf = new byte[4096];
int c;
while ((c = is.read(buf, 0, buf.length)) > 0) {
oos.write(buf, 0, c);
oos.flush();
}
}
finally { oos.close();}
MetadataChangeSet meta = new MetadataChangeSet.Builder().setTitle(titl).setMimeType(mime).build();
parent.createFile(mGoogleApiClient, meta, cont).setResultCallback(new ResultCallback<DriveFolder.DriveFileResult>() {
@Override public void onResult(DriveFolder.DriveFileResult driveFileResult) {
DriveFile dFil = driveFileResult != null && driveFileResult.getStatus().isSuccess() ?
driveFileResult.getDriveFile() : null;
if (dFil != null) {
Log.d(TAG,"photo "+count+" uploaded");
count --;
if(count == 0){
// is the task completed?
}
} else {
Log.d(TAG,"error during upload photo " + count);
}
}
});
} catch (Exception e) {
e.printStackTrace();
ShowErrorHelper.showErrorDialog(UploadActivity.this, e);
}
}
});
} catch (Exception e) {
e.printStackTrace();
ShowErrorHelper.showErrorDialog(UploadActivity.this, e);
}
}
(그래서 로컬로 제거 할 수 있습니다) : 이것은 내가 사용하고 코드입니다.
그래, 파일을 삭제할 수 있습니다. 감사합니다! 그러나 파일이 이미 클라우드에 있는지 확인하는 방법은 없습니다. 예를 들어, 작업이 완료 될 때까지 인터넷 연결을 열린 상태로 유지하고 싶습니다. 문제는 사용자가 연결을 닫고 다음날 다시 열면 클라우드에있는 파일을보기 위해 하루를 기다려야하고 거의 실시간으로 액세스 할 수 있어야한다는 것입니다. – user2044083
실시간 및 결정 론적 동작을 원하는 경우 GDAA 사용을 중지하고 REST API로 전환하십시오. – pinoyyid