4

我使用 DocumentFile 检查文件元数据和存在。这是这样实例化的:

DocumentFile df = DocumentFile.fromSingleUri(context, uri);
boolean exists = df.exists();

该文件的 uri 以前有效,直到我故意在文件系统中手动删除该文件以查看应用程序将如何反应。现在这个堆栈跟踪出现在应用程序中:

03-14 11:33:08.559 27087-27097/? E/DatabaseUtils: Writing exception to parcel
  java.lang.IllegalArgumentException: Failed to determine if primary:Download/thefile.txt is child of primary:Download: java.io.FileNotFoundException: Missing file for primary:Download/thefile.txt at /storage/emulated/0/Download/thefile.txt
      at com.android.externalstorage.ExternalStorageProvider.isChildDocument(ExternalStorageProvider.java:326)
      at android.provider.DocumentsProvider.enforceTree(DocumentsProvider.java:198)
      at android.provider.DocumentsProvider.query(DocumentsProvider.java:489)
      at android.content.ContentProvider.query(ContentProvider.java:1017)
      at android.content.ContentProvider$Transport.query(ContentProvider.java:238)
      at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
      at android.os.Binder.execTransact(Binder.java:453)
03-14 11:33:08.561 27046-27419/packagename W/DocumentFile: Failed query: java.lang.IllegalArgumentException: Failed to determine if primary:Download/thefile.txt is child of primary:Download: java.io.FileNotFoundException: Missing file for primary:Download/thefile.txt at /storage/emulated/0/Download/thefile.txt

不会使应用程序崩溃,它只会在我每次尝试使用 DocumentFile 时生成此堆栈跟踪。所以在最坏的情况下,这只是 logcat 中的一个刺激物。

我希望FileNotFoundException使用.exists(). 当我检查它是否存在以避免使用不存在的文件时。

在这种情况下是否推荐使用不同的功能?

4

1 回答 1

9

我已经处理这种烦恼太久了。你甚至不能把它包起来。我已经为此错误提交了一份错误报告:

https://code.google.com/p/android/issues/detail?id=241400&thanks=241400&ts=1489099169

添加支持,这样事情就可以更快地得到解决。

于 2017-03-09T22:44:01.340 回答