ACTION_MEDIA_SCANNER_SCAN_FILE Deprecated!
You can use the following
Java
File file = new File(filePath);
MediaScannerConnection.scanFile(context,
new String[]{file.toString()},
null, null);
Kotlin
val file = File(filePath)
MediaScannerConnection.scanFile(context, arrayOf(file.toString()),
null, null)
This will request the media scanner to scan the files at the specified path. Also, it is worth noticing that 3rd and 4th param in scanFile() method is null in the above example. However the third param can be used to optionally specify the MIME TYPE of the file and the fourth param can be used to supply a listener to listen to the scan completion event.
[Refer developer site for details][1]
[1]:
[To see links please register here]
Following is the deprecated way
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));