Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android | give image with intent

I want to pass my image from one Activity to another. At first I tried to do this with a base64 String of my image. But this only works for small pictures. It worked with 400 kb but not with 600 kb. Is there a better way to do this? By the way, I don't save the image locally, I get the image from a server, so I don't have a real Drawable.

like image 559
user6586661 Avatar asked Mar 08 '26 11:03

user6586661


1 Answers

If you only have the remote URL, then you can directly share it, otherwise you can save the image in the local media store and then share its local URL. Something like:

Bitmap bitmap = ...
String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "Image Description", null);
Uri uri = Uri.parse(path);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Image"));
like image 120
manfcas Avatar answered Mar 11 '26 00:03

manfcas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!