I've tried to add a picture on a MMS, weirdly, it's work on email but it does not show up on MMS. Any idea? I just want to open the current text message app then write a message with an image.
Uri uri = Uri.fromFile(file);
Intent mms = new Intent(Intent.ACTION_SEND);
mms.setType("image/*");
mms.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mms.putExtra("sms_body", ConstanteService.getShareURL(this.context));
mms.putExtra("address", phoneTxt);
mms.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(mms,"Send"));
Related
I am developing an app, where I want to share the TEXT and IMAGE to other apps installed on my phone.
But when I click the share button Neither it shares TEXT nor IMAGE just empty it directs me to another app I chose for sharing.
below postDescription and postImage are my methods of model class, and I checked that am I getting values are not in a toast it gives there values properly.
Below is the code:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, postDescription);
Uri uri = Uri.parse(postImage);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(shareIntent, "Share With"));
So the above bunch of code was not working, then I found code through which I can share my post TEXT and IMAGE to WhatsApp only, I tried that but it shows file formate not supported inside WhatsApp.
below is the code for sharing to WhatsApp only:
Uri imgUri = Uri.parse(postImage);
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, postDescription );
whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
whatsappIntent.setType("image/jpeg");
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
}
I want to know how to create a share button that works fine for WhatsApp and everything or only WhatsApp will do the work for me.
By removing the package from the intent, Android should display the list of apps that can handle the type of intent.
Uri imgUri = Uri.parse(postImage); //Provide the URI to the downloaded image, not an external URL
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("*/*");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, postDescription );
whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
if (whatsappIntent.resolveActivity(packageManager) != null) {
startActivity(whatsappIntent)
}
I am trying to share image and text via SMS. I am adding the image Uri but Image is not attached with SMS. What is wrong with my code please tell me Advance Thanks.
`Intent share = new Intent(Intent.ACTION_VIEW);
share.setType("image/png");
share.setData(Uri.parse("sms:"));
share.putExtra(Intent.EXTRA_SUBJECT, subject);
share.putExtra(Intent.EXTRA_TEXT, text);
Uri uri=FileProvider.getUriForFile(getActivity(),getApplicationContext().getPackageName() + ".provider",file);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(share);
I am creating an intent that will send some text and image to the messaging app. But when messaging app is opened, it only shows the image and no text with it. Can anybody help? Below is my code.
String pathofBmp = MediaStore.Images.Media.insertImage(getContentResolver(), Global.bitmap, "DriverImage", null);
Uri bmpUri = Uri.parse(pathofBmp);
Intent smsIntent = new Intent(Intent.ACTION_SEND);
smsIntent.setType("*/*");
smsIntent.setPackage("com.android.mms");
smsIntent.putExtra(Intent.EXTRA_TEXT, messageBody);
smsIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(smsIntent);
I am trying to share an image from my Android app. I am trying to send it as an Email attachment as well as a photo on WhatsApp.
The code is:
String imageUrl = Path to image (eg. sdcard/pictures/image1.jpg);
shareImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri uriToImage= Uri.parse(imageUrl);
Log.d("Image", ""+uriToImage);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share image:"));
}
});
What's happening is:
On WhatsApp I can share the image easily.
On Gmail, it says that the attachment could not be sent.
On Hangouts I get a toast which says Photo couldn't be found
On Facebook too, the post is not accompanied with the Image but I can post.
On Facebook Messenger, it crashes without opening.
The tutorial that I have followed for this is given here. The send binary content part of the tutorial is the one that I have implemented.
Another thing I tried was to set the image in an ImageView and see if it is displayed. The image is displayed correctly. Also, the log message prints the correct path of the image.
I also read and tried the answers to: Question 1 and Question 2 but to no avail.
Where am I going wrong?
try this,
try
{
File myFile = new File(share_image_path);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = myFile.getName().substring(myFile.getName().lastIndexOf(".") + 1);
String type = mime.getMimeTypeFromExtension(ext);
Intent sharingIntent = new Intent("android.intent.action.SEND");
sharingIntent.setType(type);
sharingIntent.putExtra("android.intent.extra.STREAM", Uri.fromFile(myFile));
startActivity(Intent.createChooser(sharingIntent, "Share using"));
}
catch (Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
Yes the #CommonsWare Answer is correct you missed the Schema in your Intent.putExtra() and that's why it is failing to read your image in other social media platform
Here's my solution
Uri fileUri = Uri.fromFile(new File(imagePath));
//No need to do mimeType work or ext
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share Image:"));
BTW it works on all the mentioned platform
Uri image_uri = Uri.parse("file://"+imagePath);
Another method of creating Uri and passing it to intent
I'm developing an application that share binary data (videos, musics) via bluetooth and so on. I'm using ACTION_SEND intent for that, but my device Toast a message like "File help.apk was not sent". My code is here:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("*/*");
File fayl = new File("file:///" + "mnt/apps/help.apk");
Uri uri = Uri.fromFile(fayl);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent);