Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Share Image + Text together using ACTION_SEND in android?

I want to share Text + Image together using ACTION_SEND in android, I am using below code, I can share only Image but i can not share Text with it,

private Uri imageUri; private Intent intent;  imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher"); intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Hello"); intent.putExtra(Intent.EXTRA_STREAM, imageUri); intent.setType("image/*"); startActivity(intent); 

Any help on this ?

like image 265
Hiren Patel Avatar asked Dec 02 '13 16:12

Hiren Patel


People also ask

How do I share photos with FileProvider on Android?

If you are using Recylerview Adapter to pass image in full to DetailActivity, this solution will help you share the image received in DetailActivity so that you can share with social media apps. Drawable drawable=imageView. getDrawable(); Bitmap bitmap=((BitmapDrawable)drawable).


1 Answers

you can share plain text by these codes

String shareBody = "Here is the share content body";     Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);         sharingIntent.setType("text/plain");         sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");         sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);         startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using))); 

so your full code (your image+text) becomes

      private Uri imageUri;       private Intent intent;              imageUri = Uri.parse("android.resource://" + getPackageName()                     + "/drawable/" + "ic_launcher");              intent = new Intent(Intent.ACTION_SEND); //text             intent.putExtra(Intent.EXTRA_TEXT, "Hello"); //image             intent.putExtra(Intent.EXTRA_STREAM, imageUri); //type of things             intent.setType("*/*"); //sending             startActivity(intent); 

I just replaced image/* with */*

update:

Uri imageUri = Uri.parse("android.resource://" + getPackageName()         + "/drawable/" + "ic_launcher");  Intent shareIntent = new Intent();  shareIntent.setAction(Intent.ACTION_SEND);  shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");  shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);  shareIntent.setType("image/jpeg");  shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);  startActivity(Intent.createChooser(shareIntent, "send")); 
like image 78
Ahmed Ekri Avatar answered Oct 13 '22 01:10

Ahmed Ekri