Uri content: // media / external / file does not exist for some devices

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

This is an 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()the parent directory of the file, because it is the most functional way to notify MediaScanner about the deletion of the file and how to update the MTP content. I tried all the other methods that I found here on stackoverflow (e.g. Android, how to use MediaScannerConnection scanFile ), but nothing works like this.

Btw. I use it only for API 11 and newer. External storage is definitely installed.

I have the following questions: 1. Do you know the reason for this exception? I don't want to just ignore the exception. And I do not want to delete this code when it works well for most devices. 2. Do you know any new reliable method of notifying MediaScanner and how to immediately update the contents of the MTP when a file is deleted?

+4
2

, . , ​​, , .

0

, facebook yolanda L. Hinojosa

0

Source: https://habr.com/ru/post/1524169/


All Articles