-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathCreateImageUriUseCase.kt
More file actions
30 lines (28 loc) · 1.04 KB
/
CreateImageUriUseCase.kt
File metadata and controls
30 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.example.bluromatic.domain
import android.content.ContentResolver
import android.content.ContentValues
import android.net.Uri
import android.provider.MediaStore
import androidx.annotation.RequiresApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
* Create imageUri.
*/
@RequiresApi(29)
class CreateImageUriUseCase {
suspend operator fun invoke(resolver: ContentResolver, filename: String): Uri? {
return withContext(Dispatchers.IO) {
val imageCollection =
MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
val values = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, filename)
put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures/Blur-O-Matic")
put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
put(MediaStore.Images.Media.IS_PENDING, 1)
}
val imageUri = resolver.insert(imageCollection, values)
imageUri
}
}
}