How to use media scanner scanFile() to scan a DocumentFile path on Android?
Asked Answered
O

1

9

I'm trying to use scanFile() to scan a file I have created using DocumentFile. It would appear that this function does not work with a DocumentFile's uri/path. Is there any way to get them to work together or another method to invoke the media scanner?

DocumentFile myDir = DocumentFile.fromTreeUri(getApplicationContext(),MainActivity.myStrDir).findFile("Folder").findFile("test.mp4");

scanFile(myDir.getUri().getPath());

private void scanFile(String filePath) {
        MediaScannerConnection.scanFile(mContext, new String[]{filePath},
                null, new MediaScannerConnection.OnScanCompletedListener() {
                    @Override
                    public void onScanCompleted(String file, Uri fileUri) {
                        mHandler.post(mUIUpdateHandler);
                    }
                });
}
Ophiuchus answered 23/1, 2017 at 0:52 Comment(0)
V
1

It seems, that this is not necessary. I switched from files to DocumentFiles and the created DocumentFiles show up immediately without the need to invoke scanFile().

Vhf answered 23/5, 2023 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.