To send MMS with Image - android

I have my images in drawable folder and I am getting that images in gridview.Also I am showing the perticular image on selection fullscreen.Now I want to send MMS with image attachment.
Here is my code to show the image. And to send MMS.how to get Uri to put to intent or how to send the image attachment.
imageView.setImageResource(imageAdapter.mThumbIds[position]);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "Hii");
sendIntent.setType("image/png");
startActivity(sendIntent);

Use the following code to send the mms.. Hope this wil help you.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/file.gif")));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent,"Send"));
Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");
EDIT:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hi how are you");
Uri uri = Uri.parse("android.resource:// com.example.stack/drawable/ic_launcher.png");
intent.putExtra(Intent.EXTRA_STREAM,uri );
intent.setType("image/png");
startActivity(Intent.createChooser(intent,"Send"));

Related

Add image to `Intent.ACTION_SENDTO`

I am sending a sms to multiple recipients using Intent.ACTION_SENDTO
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.putExtra(Intent.EXTRA_TEXT, strMessage);
intent.setData(Uri.parse("smsto:" + Uri.encode(getPhoneNumbers())));
startActivity(intent);
However now I want to add a image to the sms. Is there any way to do this with Intent.ACTION_SENDTO I tried adding below code with no success....
Uri path = Uri.parse("android.resource://packagename/" + R.drawable.icon);
intent.putExtra(Intent.EXTRA_STREAM, path);
intent.setType("image/png");

Send text and image to specific contact (whatsapp)

I wanted to know how I can send text and image to a specific whatsapp contact. I found some code to view a specific contact, but not to send data.
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", smsText);
i.setPackage("com.whatsapp");
startActivity(i);
But that code just opening the chat history, but doesn't take the text and image and send it.
I also try the below code for send image and text via whatsApp but that ask for choose the contact for send
Intent shareIntent = new Intent();
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, sendString);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent. setPackage ("com. whatsapp");
startActivity(shareIntent);
If that functionality is possible then please give me a suggestion for this.
Solution :
Intent sendIntent = new Intent("android.intent.action.SEND");
File f=new File("path to the file");
Uri uri = Uri.fromFile(f);
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker"));
sendIntent.setType("image");
sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("919xxxxxxxxx")+"#s.whatsapp.net");
sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image");
startActivity(sendIntent);
Refer to my answer at for detailed explanation.
https://stackoverflow.com/a/41805567/3989718

How to send multimedia messages with android intent?

I'm trying to send an multimedia message(with an image) through an intent.How should I build the intent?
I've tried the code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/documents/aaa.png")));
I can select mms app(Textra) from chooser dialog to send the image. But the chooser dialog lists other apps(such as Google Keep).
Then I tried this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"));
Only mms apps appears now.But I don't know how to attach my image.
Is there any solution for that?
try this may help,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intent.putExtra("sms_body", "write some text here");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/documents/whatever.png")));
intent.setType("image/*");
startActivity(intent);
Try this way,hope this will help you to solve your problem.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "some text");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/documents/aaa.png")));
intent.setType("image/png");
startActivity(intent);

how to share images from my app to whatsapp?

Here i am sharing images from my app to whatsapp.but this code is working here only for mylist1[i] and not for mylist2[i] and mylist3[i]. As in my activity file there are 15 images in every list. what to do?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.example.drawcelebrities/"+mylist1[i]+mylist2[i]+mylist3[i]);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share via"));
Take image array in mylist[] and use below code, then share image via whatsapp.
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+mylist[i]);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));
If I'm not wrong then for that you should use android.content.Intent.ACTION_SEND_MULTIPLE..Refer this link it will help you..
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg");
ArrayList<Uri> files = new ArrayList<Uri>();
for(String path : filesToSend /* List of the files you want to send */) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
files.add(uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);

how to attach image from drawable folder to gmail in android?

I my application I have to attach an image from drawable folder to email client.
I have no idea how to do it.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
Uri path = Uri.parse("android.resource://your.package.name/" + R.drawable.sample_1);
intent.putExtra(Intent.EXTRA_STREAM, uri);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png");

Categories

Resources