Uri content://media/external/file doesn't exist for some devices
Asked Answered
W

1

6

I have an issue with some devices. I cannot replicate it on any device but I have quite a lot of crash reports reported by some users.

It is this exception:

java.lang.IllegalArgumentException: Unknown URL content://media/external/file
    at android.content.ContentResolver.delete(ContentResolver.java:1024)

I use this:

context.getContentResolver().delete(MediaStore.Files.getContentUri("external"), MediaStore.Files.FileColumns.DATA + "=?", new String[] { path });

After that I call MediaScannerConnection.scanFile() on file's parent directory, because it is imho most functional way how to notify MediaScanner about deletion of file and how to refresh MTP content. I tried all other ways that I have found here on stackoverflow (e.g.Android How to use MediaScannerConnection scanFile) but nothing is working as well as this.

Btw. I use it only for APIs 11 and newer. External storage is certainly mounted.

I have these questions: 1. Do you know any reason why this exception occurs ? I don't want just to ignore the exception. And I don't want to remove this code when it works quite good for most devices. 2. Do you know some new reliable method how to notify MediaScanner and how to refresh immediately content of MTP when some file is deleted ?

Watchman answered 28/1, 2014 at 21:26 Comment(2)
This is pretty strange, especially since an almost identical call is part of testMediaScanner in the CTS. Do you know what types of devices are crashing? Is it limited to a manufacturer/model/OS?Reflect
#21417711Reinert
H
0

Most probably it has to do with caching on the device. Catching the exception and ignoring is not nice but my problem was fixed and it seems to work.

Hyperesthesia answered 2/11, 2016 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.