I have a DocumentsProvider
that simply republishes a directory from an external file storage. Everything works well, however when deleting a file from the Android Files application, the directory does not get refreshed after the file is deleted. I'm probably supposed to call contentResolver.notifyChange
, but I'm struggling to find the proper content uri.
@Throws(FileNotFoundException::class)
override fun deleteDocument(documentId: String) {
val file = getFileForDocId(documentId)
if (!file.delete()) {
throw FileNotFoundException("Failed to delete document with id $documentId")
}
// Notify parent about directory change
file.parentFile?.let { parent ->
val parentDocId = getDocIdForFile(parent)
val updatedUri = DocumentsContract.buildChildDocumentsUri(
BuildConfig.FILES_AUTHORITY, parentDocId)
context!!.contentResolver.notifyChange(updatedUri, null)
}
}
I tried many combinations with the Uri, but it still doesn't work. I even tried to make all the identifiers in URL lowercase, no luck. The only thing that seemed to have at least some effect was trying to refresh the root
- it forced queryRoots
.
Deleting the file on the Google Drive seems to trigger the proper refresh, so there is probably some way.