Using the SAF provided in KitKat, the MediaScanner is not called on files saved to the internal or external storage points of a device. As such I have to determine based on the returned URI if I should attempt to run MediaScanner.
// The SAF uses content URI to pass meta about the file. The following host is used for internal storage.
if (mExportServiceUri.getHost().equals("com.android.externalstorage.documents")) {
final File externalStorage = Environment.getExternalStorageDirectory();
final String path = mExportServiceUri.getEncodedPath().replace("/document/primary%3A", "");
MediaScannerConnection.scanFile(mService.getApplicationContext(), new String[] { new File(
externalStorage, path).getAbsolutePath() }, null, null);
}
Has anyone else had to work around this issue and if so, is there a better approach than this? Currently this only supports the device external storage and additional storage space such as the SDCard need to be handled in a separate check.