Skip to content

Commit 0a80c6c

Browse files
authored
Fix: use application context for content resolver (#671)
1 parent 08d7f7e commit 0a80c6c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

misc/src/main/java/com/example/snippets/ai/GeminiDeveloperApiSnippets.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.example.snippets.ai
1818

19-
import android.content.ContentResolver
19+
import android.app.Application
2020
import android.graphics.Bitmap
2121
import android.net.Uri
2222
import com.google.firebase.Firebase
@@ -80,12 +80,13 @@ fun textAndImageInput(scope: CoroutineScope, bitmap: Bitmap) {
8080
@Suppress("unused")
8181
fun textAndAudioInput(
8282
scope: CoroutineScope,
83-
contentResolver: ContentResolver,
83+
applicationContext: Application,
8484
audioUri: Uri
8585
) {
8686
val model = GeminiDeveloperApi25FlashModelConfiguration.model
8787
// [START android_gemini_developer_api_multimodal_audio_input]
8888
scope.launch {
89+
val contentResolver = applicationContext.contentResolver
8990
contentResolver.openInputStream(audioUri).use { stream ->
9091
stream?.let {
9192
val bytes = it.readBytes()
@@ -105,12 +106,13 @@ fun textAndAudioInput(
105106
@Suppress("unused")
106107
fun textAndVideoInput(
107108
scope: CoroutineScope,
108-
contentResolver: ContentResolver,
109+
applicationContext: Application,
109110
videoUri: Uri
110111
) {
111112
val model = GeminiDeveloperApi25FlashModelConfiguration.model
112113
// [START android_gemini_developer_api_multimodal_video_input]
113114
scope.launch {
115+
val contentResolver = applicationContext.contentResolver
114116
contentResolver.openInputStream(videoUri).use { stream ->
115117
stream?.let {
116118
val bytes = it.readBytes()

0 commit comments

Comments
 (0)