Junior
Is it possible to pass a photo through an Intent?
sobes.tech AI
Answer from AI
Yes, it is possible.
-
Sharing URI: The most common and effective way is to share the URI of the photo file.
val imageUri = Uri.fromFile(File(imagePath)) // imagePath - path to the file val shareIntent = Intent(Intent.ACTION_SEND).apply { type = "image/*" // MIME type of the image putExtra(Intent.EXTRA_STREAM, imageUri) // Sharing URI addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // Grant read permission for URI } startActivity(Intent.createChooser(shareIntent, "Share Image")) -
Sharing Bitmap (not recommended for large images): You can serialize the Bitmap and put it into Extra. However, this is not recommended for large images due to Intent extras size limitations (usually up to 1MB) and potential OutOfMemoryError.
val bitmap: Bitmap = ... // Your Bitmap val bitmapIntent = Intent(...).apply { putExtra("image_bitmap", bitmap) // Bitmap must be Parcelable } startActivity(bitmapIntent)When receiving:
val receivedBitmap: Bitmap? = intent.getParcelableExtra("image_bitmap")
The best approach for sharing photos between apps is to use URI with read permission (FLAG_GRANT_READ_URI_PERMISSION), especially if dealing with media files stored in storage. Directly passing Bitmap via Extra is only suitable for very small images or thumbnails.