I want to share image and text like:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(url);
i.setData(u);
startActivity(intent);
Kindly find the below code.
Uri path= Uri.parse("android.resource://" + this.getPackageName()
+ "/drawable/" + "image_name");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Testing");
shareIntent.putExtra(Intent.EXTRA_STREAM, path);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Using"));
Related
Below this code i try to share text with video but it only share video,text not share with video.
please help if any one have solution of my issue.
String path="android.resource://" + "com.avani.videoviewdemo" + "/" + R.raw.ae_kaash_kahi;
//Intent a = getIntent();
file=new File(path);
str=arrayList.get(position).getVideoName();
Log.e("video_name", ""+arrayList.get(position).getVideoName()); Log.e("video_name",""+ str);
id = context.getResources().getIdentifier(str, "raw", context.getPackageName()); Uri uri = Uri.parse("android.resource://" + context.getPackageName() + "/" + id);
DownloadFile();
Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri screenshotUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file); sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); sharingIntent.putExtra(Intent.EXTRA_TEXT, "From FullScreenVideoStatus"); sharingIntent.setType("video/*"); context.startActivity(Intent.createChooser(sharingIntent, "Share video using"));
For set caption in video/image in share intent, just set text in:
sharingIntent.putExtra(Intent.EXTRA_TITLE, "Your text caption");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/mp4"); //If it is a 3gp video use ("video/3gp")
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/ae_kaash_kahi";
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Video Title");
startActivity(Intent.createChooser(sharingIntent, "Share Video!"));
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "TEMPORARY"); // for text share
intent.putExtra(Intent.EXTRA_STREAM, uri); // for media share
intent.setType("image/*"); // this line is use to filter which app support specified media formate to share
startActivity(intent);
you can use video/* for video file here i have used image/* for image share
I am looking to add a text message under an image (not printed on the image) so when I click a share button, the image, and text message to be shared as one message that looks like this:
My code to share an image looks like this:
public void shareImage(View view) {
Intent shareIntent = new Intent();
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
How can I add the text Image created by: abcd.com under the image, (as a text not printed on the image) in the same text message or email etc.
Try this
Uri imgUri = Uri.fromFile(new File(DIRECTORY + "/" + fileName));
//Add this code if you get SecurityException error
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Text you want to attach with image.");
startActivity(Intent.createChooser(shareIntent, "Share Image"));
The following snippet of code should work. We add the image to MediaStore.
public void shareImage(View view) {
Intent shareIntent = new Intent();
shareIntent.putExtra(Intent.EXTRA_TEXT, Constant.SHARE_MESSAGE
+ Constant.SHARE_URL);
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
Bitmap bm = BitmapFactory.decodeFile(photoURI);
String url= MediaStore.Images.Media.insertImage(this.getContentResolver(), bm, "title", "description");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
A simple case of sharing a bitmap to Twitter/Whatsapp/Facebook Messenger was resolved thanks to #Aniruddh Chandratre solution. MediaStore.Images.Media.insertImage returns a String in content://media format i.e. content://media/external/images/media/610
val savedImageURI = MediaStore.Images.Media.insertImage(
activity.contentResolver, bitmap, "title", "decription")
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(savedImageURI))
shareIntent.type = "image/*"
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
activity.startActivity(Intent.createChooser(shareIntent, "Share Image"))
On Android I try to share image + text like this :
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"));
this work fine on Whatsapp (for example) but on viber it's show only the image and skip the text :( On Instagram it's the total opposite, text is send but not the image ...
How can i do ?
Try this for viber :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.viber.voip");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Message");
Checkout this answer for the Instagram part : https://stackoverflow.com/a/16299999
Hope this helps !!
Tried with below code and its going image but not text through messaging and it works fine with email, whatsapp. can any one suggest me how to do it
Uri shareImageUri = saveBitmapImage(result);
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_STREAM, shareImageUri);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Hiiiiiiiiiiiiiiiiiiiiiiii");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"byeeeeeeeeeeee");
emailIntent.setType("image/png");
mActivity.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Try this code:
String fileName = "image_file_name.jpg";//Name of an image
String externalStorageDirectory = Environment.getExternalStorageDirectory().toString();
String myDir = externalStorageDirectory + "/saved_images/"; // the file will be in saved_images
Uri uri = Uri.parse("file:///" + myDir + fileName);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test Mail");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Launcher");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share Image and Text"));
or
File filePath = getFileStreamPath("share_image.jpg"); //optional //internal storage
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "share content");
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath))); //optional//use this when you want to send an image
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "share"));
I receive an error when I press a Button.
InputStream y11 = getResources().openRawResource(R.drawable.step_000);
Bitmap b11 = BitmapFactory.decodeStream(y11);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.setPackage("com.whats app.android");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, b11);
startActivity(Intent.createChooser(intent, "Share with"));
You can try like this;
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
Uri uri = Uri.parse("android.resource://your package name/"+R.drawable.ic_launcher);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, This is test Sharing");
startActivity(Intent.createChooser(shareIntent, "Send your image"));
Also look into this: Returning an Image to whatsapp