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"));
Related
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"))
Hi there is the code i used to share text and image :
Toast.makeText(App.getContext(), "Share", Toast.LENGTH_LONG).show();
Intent sharingIntent = null;
if(!image_resource.isEmpty()){
sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
String imagePath = "SD-Card Path";
ExceptionHelpers.dLog("SHARE_LOG", "Share image path : " + imagePath);
ExceptionHelpers.dLog("SHARE_LOG", "Share image exist : " + (new File(imagePath).exists())); // It return 'true' on LogCat
if(new File(imagePath).exists()) {
ExceptionHelpers.dLog("SHARE_LOG", "Share image and text");
Uri imageUri = Uri.fromFile(new File(imagePath));
sharingIntent.setType("*/*"); // also 'image/*' tested and not works
sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
}else{
ExceptionHelpers.dLog("SHARE_LOG", "Share text");
sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
}
}else {
ExceptionHelpers.dLog("SHARE_LOG", "Share text");
sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
}
String shareBody = ""+App.getString(R.string.this_text_shared_from)+" : "+App.getString(R.string.app_name)+" "+App.getString(R.string.share_text_2)+" \n "+
App.getString(R.string.share_about);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "" + App.getString(R.string.app_name));
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "" + App.getString(R.string.share_via)));
App is my custom class and App.getString is :
public static String getString(int resId){
return App.context.getString(resId);
}
it don't works well on Telegram, Gmail and same Apps And only share text with out Image
i found the answer for it, it work for me and i sent text and image both in one message to Telegram app.here is my code.
Intent intent = new Intent(Intent.ACTION_SEND);
packageName="org.telegram.messenger";
intent.setPackage(packageName);
//this is my art....
intent.setType("image/text/plain");
path=getBitMapPath();//this is path of image
uri = Uri.parse(path);
putExtra(Intent.EXTRA_STREAM, uri);
putExtra(Intent.EXTRA_TEXT, "hello telegram. i do it!");
ss = Intent.createChooser(intent, "hamid");
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ss);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
else
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.setType("image/*");
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getActivity().startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));
In my application, My requirement is to send Image and text simultaneously. So I use the following code
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_TEXT, "My photos");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+f));
startActivity(Intent.createChooser(share, "Share Image"));
But only the image is sended but the text is not sending. How can I solve this problem?
plz try this
//assuming uris is a list of Uri
Intent intent = null;
if (uris.size > 1){
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, "Some message");
startActivity(Intent.createChooser(intent,"compatible apps:"));
You are setting the MIME type of that Intent to image that's why only the image is sent.
Something like this will solve your problem:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
share.putExtra(Intent.EXTRA_TEXT, "My photos");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///"+f));
startActivity(Intent.createChooser(share, "Share Image"));
String message= "My photos";
URI = Uri.parse("file://" + f);
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("*/*");
if (URI != null) {
share.putExtra(Intent.EXTRA_STREAM, URI);
}
share.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(share, "Share Image"));
This way should be ok.
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"));
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