This commit is contained in:
Thibault Deckers 2024-08-04 20:17:33 +02:00
parent 4d80dfe1d6
commit f824eedf63

View file

@ -59,7 +59,14 @@ class MediaStoreHandler(private val context: Context) : MethodCallHandler {
private fun getGeneration(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) { private fun getGeneration(@Suppress("unused_parameter") call: MethodCall, result: MethodChannel.Result) {
val generation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { val generation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
MediaStore.getGeneration(context, MediaStore.VOLUME_EXTERNAL_PRIMARY) try {
MediaStore.getGeneration(context, MediaStore.VOLUME_EXTERNAL_PRIMARY)
} catch (e: Exception) {
// may yield `IllegalArgumentException: Volume external_primary not found`
val volumes = MediaStore.getExternalVolumeNames(context).joinToString(", ")
result.error("getGeneration-primary", e.message + " (available volumes are $volumes)", e)
return
}
} else { } else {
null null
} }