send sms with a preset phone number - android

I want to send an sms message and this code snippet works:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "Check out this Punchit app!
https://market.android.com/details?id=com.punchit");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Now I want to preset the phone number and tried both of the following:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("tel:9999999999" ));
and
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER, "9999999999");
Neither of these two statements work, so what is the correct syntax for presetting a phone number?

test as follows:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "Hello1");
sendIntent.putExtra("address", "12345");
sendIntent.setType("vnd.android-dir/mms-sms")

Related

Send a text message for a specific number using WhatsApp

I'm trying to open WhatsApp with both text message and phone number, the phone number is OK but the message are not being displayed
Here's my code:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.SetComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.SetType("text/plain");
sendIntent.PutExtra("jid", phone_number + "#s.whatsapp.net");
sendIntent.PutExtra(Intent.ExtraText, "extra_text test");
sendIntent.PutExtra("sms_body", "sms_body test");
sendIntent.PutExtra("body", "body test");
sendIntent.PutExtra("text", "text test");
context.StartActivity(sendIntent);
I've tried all these "PutExtra" options but it's not working.
Thanks in advance!
What they allow via Intent extras is limited.
C# Example:
var sendIntent = new Intent();
sendIntent.SetPackage("com.whatsapp");
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText, "StackOverflow.");
sendIntent.SetType("text/plain");
StartActivity(sendIntent);
Ref: https://www.whatsapp.com/faq/android/28000012

Message with phone number and sms_body via whatsapp android

I have this code to send message via whatsapp
Uri uri = Uri.parse("smsto:" + PhoneNumber);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra("sms_body", "Some text");
startActivity(sendIntent);
but when whatsapp is started it filled with the phone number but not with the text provided (also i've tried with Intent.EXTRA_TEXT)

send a jpg image throug MMS using HTC

I am trying to send a jpg image through MMS using an HTC device (2.3.5, HTC Desire HD-Sense), I am using the following snippet
File sendfilepath = new File("file://" + sendfile);
Uri urimms = Uri.fromFile(sendfilepath);
Intent sendIntent = new Intent("android.intent.action.SEND_MSG");
sendIntent.putExtra(Intent.EXTRA_STREAM, urimms);
sendIntent.setType("image/jpeg");
startActivity(sendIntent);
It opens the Messaging app but it does not attach the image. I do not know why? It shows a toast "Cannot load message"
Something like this should work:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mmsto:<number>");
intent.putExtra("address", <number>);
intent.putExtra(Intent.EXTRA_STREAM, urimms);
intent.setType("image/jpeg");
startActivity(intent);
Otherwise these links look to be a little outdated but you should be able to translate everything pretty well:
Android MMS Intent with with Image and body text
http://androidforums.com/application-development/25988-send-image-action_send.html
try this
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/image_4.png"));
sendIntent.setType("image/png");
startActivity(sendIntent);;

Sending MMS does include the "sms_body"

I am trying to send an image via an MMS using the following code
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "Hi there");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png");
It opens the Messaging apps and attach the message but it did not write the "sms_body" which is in my case "Hi there". Why?
try this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intent.putExtra("subject", "subject");
intent.putExtra("sms_body", "Hi there");
intent.putExtra("address", "Phonenumber");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
intent.setType("image/png");
startActivity(intent);
What seems to be working well is I just added EXTRA_TEXT (a solution which #yasserbn provided in a comment):
intent.putExtra(intent.EXTRA_TEXT, default_message);
in addition to:
intent.putExtra("sms_body", default_message);
And it seems to work whether it gets converted to multimedia message or sent as regular SMS.

How to pass phone number to mms

I have following code, which invoke mms client and attaches to it a picture
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra("address", phoneNumber);
sendIntent.putExtra(Intent.EXTRA_STREAM, mCurrItemUri);
sendIntent.setType("image/*");
getContext().startActivity(
Intent.createChooser(sendIntent, "Send MMS..."));
The problem I am facing is that I cannot pass phone number to that intent.
And Is there any way to pass an array of phone numbers to it?
Thank you on advance.
I think you need to set proper type for mms. for example:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
...
...
For more info, read this.

Categories

Resources