use the ACTION_MEDIA_SCANNER_SCAN_FILE intent at rescanning paths

This commit is contained in:
tibbi 2019-12-03 22:16:58 +01:00
parent b71857b851
commit dfba507808
2 changed files with 9 additions and 1 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.20.3'
propVersionName = '5.20.4'
kotlin_version = '1.3.61'
}

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.commons.extensions
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.hardware.usb.UsbConstants
import android.hardware.usb.UsbManager
import android.media.MediaScannerConnection
@ -259,6 +260,13 @@ fun Context.rescanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null
return
}
for (path in paths) {
Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE).apply {
data = Uri.fromFile(File(path))
sendBroadcast(this)
}
}
var cnt = paths.size
MediaScannerConnection.scanFile(applicationContext, paths.toTypedArray(), null) { s, uri ->
if (--cnt == 0) {