mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
(android) Trigger media scan on downloaded file
This commit is contained in:
parent
02ff3a0d70
commit
84cf8ee7ae
1 changed files with 12 additions and 0 deletions
|
@ -4,6 +4,7 @@ import android.Manifest
|
|||
import android.app.Activity
|
||||
import android.content.ContentValues
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
|
@ -103,9 +104,20 @@ class MediaStoreChannelHandler(activity: Activity)
|
|||
BufferedOutputStream(FileOutputStream(file)).use {
|
||||
stream -> stream.write(content)
|
||||
}
|
||||
|
||||
val fileUri = Uri.fromFile(file)
|
||||
triggerMediaScan(fileUri)
|
||||
result.success(null)
|
||||
}
|
||||
|
||||
private fun triggerMediaScan(uri: Uri) {
|
||||
val scanIntent = Intent().apply {
|
||||
action = Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
|
||||
data = uri
|
||||
}
|
||||
_context.sendBroadcast(scanIntent)
|
||||
}
|
||||
|
||||
private val _activity = activity
|
||||
private val _context get() = _activity
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue