如何查看使用GoogleDrive API的上传进度?
的.service.files()插入(身体,mediaContent).execute(); 只返回一个文件,我们可以检查文件是否完全上传.
但我需要实时检查进度(至少每秒钟左右),无论如何要做到这一点?
对于下载部分,我认为我们可以手动比较我们已经从输入流读取的总字节数的字节数,然后计算当前进度.
但这是正确的方法吗?还是有其他更好的检查进度的方法?
private void saveFileToDrive() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
// File's binary content
java.io.File fileContent = new java.io.File(fileUri.getPath());
FileContent mediaContent = new FileContent("image/jpeg", fileContent);
// File's metadata.
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("image/jpeg");
File file = service.files().insert(body, mediaContent).execute();
if (file != null) {
showToast("Photo uploaded: " + file.getTitle());
//startCameraIntent();
}
} catch (UserRecoverableAuthIOException e) {
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (IOException …
Run Code Online (Sandbox Code Playgroud)