Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. context.contentResolver.delete(uri, null, null)
  2.  
  3. class MediaScanner {
  4. fun trigger(ctx: Context, path: String, callback: (isExecuted: Boolean) -> Unit) {
  5. runCatching {
  6. if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  7. val files = FileUtils().listFiles(File(path), null, true)
  8. val mList: MutableList<String> = arrayListOf()
  9. files.forEach {
  10. mList.add(it.absolutePath)
  11. }
  12. MediaScannerConnection.scanFile(ctx, mList.toTypedArray(), null, null)
  13. } else {
  14. ctx.sendBroadcast(Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://${File(path).absolutePath}")))
  15. }
  16. }.onSuccess { callback(true) }.onFailure { callback(false) }
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement