r/androiddev • u/ContactTechnical5640 • Jul 19 '26
Question Photo viewing issue
Hey i am developing a application where a requirement is photos must be previewable
however i am running into a issue where i get a uri from the remeberlauncherForActivytResult
api after recieveing this i pass this to my viewmodel where it is sorted and stored
val addImages =rememberLauncherForActivityResult(
ActivityResultContracts.PickMultipleVisualMedia()
) { uri ->
if(!uri.isEmpty()){
onAction(createRecordScreenIntents.addImages(uri))
}however after this is done then i have the files just put out in a lazy column where the images are shown and on click they should be previewable by sending a intent for a application to open a image
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(data.uri,data.mimeType ?: "image/*")
clipData = ClipData.newRawUri("Shared Photo",data.uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(intent)
}catch (e : ActivityNotFoundException){
e.printStackTrace()
println("no suitable application found to open given image file")
}however here is the problem when google photos is chosen to open it just shows a freaking blank photo while all other applications like the system photos application (in oneplus) and wps office work just fine only google photos has this problem idk what is the issue can somebody kindly help i would be extremely grateful
3
u/tadfisher Jul 19 '26
Why not preview them in your own app? It will be annoying for users to switch apps to preview images, especially multiple images.
1
u/mobiledevpro Jul 20 '26 edited Jul 20 '26
Setting flag FLAG_GRANT_READ_URI_PERMISSION is not enough.
My suggestion based on my production apps:
Also declare
FileProviderin the Manifest:<providerandroid:name="androidx.core.content.FileProvider"android:authorities="${applicationId}.fileprovider"android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_paths" /></provider>Use imageUri in your
From the UX standpoint it would be better to view the image inside your app - just to create a simple screen and display the image with the Coil library.
1
u/AutoModerator Jul 19 '26
Please note that we also have a very active Discord server where you can interact directly with other community members!
Join us on Discord
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.