我正在制作一个最小的可行示例,以演示How to avoid from always loading cached app data from Google Drive中描述的错误
我已在https://github.com/yccheok/google-drive-bug
完成了代码该代码旨在更新现有文本文件或写入新文本文件。
然而,在测试时,我总是在driveContents.commit
Status status;
try {
status = driveContents.commit(googleApiClient, null).await();
} catch (java.lang.IllegalStateException e) {
// java.lang.IllegalStateException: DriveContents already closed.
Log.e(TAG, "", e);
return false;
}
例外的细节如下。
java.lang.IllegalStateException: DriveContents already closed.
at com.google.android.gms.drive.internal.zzv.zza(Unknown Source)
at com.google.android.gms.drive.internal.zzv.commit(Unknown Source)
at org.yccheok.demo.Utils.saveToGoogleDrive(Utils.java:233)
at org.yccheok.demo.SaveFile123Task.doInBackground(SaveFile123Task.java:13)
at org.yccheok.demo.SaveFile123Task.doInBackground(SaveFile123Task.java:10)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
我已经调试了很长时间,但仍然不知道为什么。我认为我没有错过任何步骤。
SAVE 123.TXT" WITH CONTENT "123"
按钮。不确定我错过了哪些步骤,导致此行始终抛出异常 - https://github.com/yccheok/google-drive-bug/blob/master/app/src/main/java/org/yccheok/demo/Utils.java#L233
谢谢。
答案 0 :(得分:0)
根据https://developers.google.com/android/reference/com/google/android/gms/drive/DriveContents
提交此DriveContents实例后,用于 创建或丢弃,它变得封闭和任何后续方法 call将抛出IllegalStateException。
我不应在driveContents.commit
之后致电driveFolder.createFile
。
我通过https://github.com/yccheok/google-drive-bug/commit/70919dcfe3fd9108c3af9ecf939a6c0ef03e07cc
进行了修复