How to share images and text in ACTION_SEND for android Development,
I want to use ACTION_SEND to share images and text. I run the following code. Currently, I can only share images and text. How can I share them?
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);
// How can I share images?
Solution
You can share the following code:
String body = "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, plain body );
StartActivity (Intent. createChooser (sharingIntent, getResources (). getString (R. string. pai_using )));
So all your code (image + text) needs to become
private Uri imageUri;private Intent intent; imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher"); intent = new Intent(Intent.ACTION_SEND);//textintent.putExtra(Intent.EXTRA_TEXT, "Hello");//imageintent.putExtra(Intent.EXTRA_STREAM, imageUri);//type of thingsintent.setType("*/*");//sendingstartActivity(intent);
Replace image/* */*
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"));
Address: http://www.itmmd.com/201411/214.html
This article is organized and published by Meng IT personnel. The reprinted article must indicate the source.