我在android中使用谷歌adrive api版本3库。上传文件不是问题,但我没有获得媒体进行中的值来显示进度条。 我的代码是,
Drive.Files.Create create = mService.files().create(file, mediaContent);
MediaHttpUploader uploader = create.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setProgressListener(new MediaHttpUploaderProgressListener() {
@Override
public void progressChanged(MediaHttpUploader uploader) throws IOException {
Intent intent = new Intent(AuthPreferences.DRIVE_FILE_UPLOAD_PROGRESS_LISTENER);
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
//postToDialog("Initiation Started");
break;
case INITIATION_COMPLETE:
//postToDialog("Initiation Completed");
break;
case MEDIA_IN_PROGRESS:
// postToDialog("Upload in progress");
intent.putExtra(AuthPreferences.DRIVE_FILE_UPLOAD_PROGRESS, (int) uploader.getProgress());
break;
case MEDIA_COMPLETE:
//postToDialog("Upload Completed!");
intent.putExtra(AuthPreferences.DRIVE_FILE_UPLOAD_PROGRESS, 100);
break;
case NOT_STARTED:
//postToDialog("Not Started!");
break;
}
sendBroadcast(intent);
}
});
file = create.execute();
在此,它正在触发INITIATION_STARTED,MEDIA_COMPLETE但未获得MEDIA_IN_PROGRESS。我也给了chunkSize但没用。我试过setDirectUploadEnabled都是真的&虚假但没用。它不起作用。版本3 API中是否有任何问题。