Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach a Bitmap when launching ACTION_SEND intent

Tags:

I have this code:

 Intent intent = new Intent();   intent.setAction(Intent.ACTION_SEND);   startActivity(intent);  

Which will successfully launch a Messaging App on Android.

But how can I attach a Bitmap object when launching the intent?

I have read http://developer.android.com/reference/Android/content/Intent.html, the closet thing to what I need is EXTRA_STREAM, like this:

intent2.putExtra(Intent.EXTRA_STREAM, _uri);

But my case, I have a reference of Bitmap object, not an URI of a Bitmap.

Please tell me what to do to attach a Bitmap object?

like image 419
KCRaju Avatar asked Jun 18 '13 04:06

KCRaju


People also ask

What is intent setType in Android?

setType(String mimeType) input param is represent the MIME type data that u want to get in return from firing intent(here myIntent instance). by using one of following MIME type you can force user to pick option which you desire. Please take a Note here, All MIME types in android are in lowercase.

Is intent deprecated?

The Intent is not deprecated the problem is with your itemClickable. class because it is not recognized.

What is intent in Android stackoverflow?

An Intent is an "intention" to perform an action; in other words, a messaging object you can use to request an action from another app component.


2 Answers

    String pathofBmp = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);     Uri bmpUri = Uri.parse(pathofBmp);     final Intent emailIntent1 = new Intent(     android.content.Intent.ACTION_SEND);     emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     emailIntent1.putExtra(Intent.EXTRA_STREAM, bmpUri);     emailIntent1.setType("image/png"); 

Where bitmap is your bitmap object which must be store in SD Card. and then use that Uri for shareimage.

like image 142
Sagar Maiyad Avatar answered Sep 20 '22 22:09

Sagar Maiyad


You must first save the bitmap to a file. you can save it to the app's cache

private void shareBitmap (Bitmap bitmap,String fileName) {     try {         File file = new File(getContext().getCacheDir(), fileName + ".png");         FileOutputStream fOut = new FileOutputStream(file);         bitmap.compress(CompressFormat.PNG, 100, fOut);         fOut.flush();         fOut.close();         file.setReadable(true, false);         final Intent intent = new Intent(     android.content.Intent.ACTION_SEND);         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));         intent.setType("image/png");         startActivity(intent);     } catch (Exception e) {         e.printStackTrace();     }  } 
like image 36
Gil SH Avatar answered Sep 19 '22 22:09

Gil SH