Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- context.contentResolver.delete(uri, null, null)
- class MediaScanner {
- fun trigger(ctx: Context, path: String, callback: (isExecuted: Boolean) -> Unit) {
- runCatching {
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- val files = FileUtils().listFiles(File(path), null, true)
- val mList: MutableList<String> = arrayListOf()
- files.forEach {
- mList.add(it.absolutePath)
- }
- MediaScannerConnection.scanFile(ctx, mList.toTypedArray(), null, null)
- } else {
- ctx.sendBroadcast(Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://${File(path).absolutePath}")))
- }
- }.onSuccess { callback(true) }.onFailure { callback(false) }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement