Android - Send SMS and make the text not editable - android

String number = "0707775544";
Uri uri = Uri.parse(number);
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, uri);
smsIntent.putExtra("sms_body", "Hello world!");
startActivity(smsIntent);
When I run this code, Android's default SMS opens up and I can of course send this. My question is: is there anyway I can make the the text "Hello world!" NOT editable, and if you want to write a personal message, it gets below this "Hello world!".
Thanks in advance!

If i got the question right, SmsManager is your solution.
This tutorial might also be usefull.

see this tutorial
http://android10.org/index.php/articlesfullapplications/241-sms-messaging-in-android-send-and-receive
you can customize the layout to disable the part you don't want changed then send the message directly

Related

How to check sent text in OnActivityResult?

I need to be able to check if the user has sent the text I set in my code;
Intent messageIntent = new Intent(Intent.ACTION_SEND)
messageIntent.putExtra(Intent.EXTRA_TEXT, "Text I want to send");
or has changed the prefixed text (on the SMS client app, email client app, or the app that gets launched by the intent) before sending it.
I need to know this because sharing my game link will give a reward to the user, so I need to check if that link is correctly shared.
I would appreciate any answer that could help.
Thanks.
ACTION_SEND isn't documented to return a result. So starting the intent with startActivityForResult() will return the default result: RESULT_CANCELED. That is, unless the receiving app has implemented support for returning a result; which is highly unlikely because it's not part of the documented behavior.
In summary, what you want to do is not possible with any of the common Intents.
You can try this...
String message = "Your Message";
intent.putExtra("IDENTIFIER", message);
And where you are going to receive the message...
String messageReceived = getIntent().getExtras().get("IDENTIFIER").toString();

SmsManager, send attachment in sms

How do I add an "attachment" into my SmsManager object when I'm trying tro send an sms?
My current function for sending a normal sms is:
public void send() {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(this.number, null, this.message, null, null);
}
I have looked a little bit at the sendDataMessage() but don't really understand it.. any help is appreciated.
Thanks.
EDIT
I don't want to use Intent for this. I have a List with Bitmap images that I want to send via an SMS/MMS. So I don't want to invoke the SMS app in my application. I want to send attachments "dynamically" depending on what's in my List.
SOLUTION
A friend of mine just posted me this link to a library: https://github.com/klinker41/android-smsmms
Message mMessage = new Message(textToSend, addressToSendTo);
mMessage.setImage(mBitmap); // not necessary for voice or sms messages
mMessage.setType(Message.TYPE_SMSMMS); // could also be Message.TYPE_VOICE
Haven't tried it yet, but it seems to be the real deal. Hope it's for good use for someone else too.
follow the code
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
and add permission
<uses-permission android:name="android.permission.SEND_SMS" />

Send Image and Text both using ACTION_SEND or ACTION_SEND_MULTIPLE

- We have tried to post image and text using the below code:
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("image/png");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/UserImages/"+ ParseUser.getCurrentUser().getObjectId() + ".png"));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hello test");
startActivity(Intent.createChooser(shareIntent,"Share"));
- We have also tried using shareIntent.setType("*/*"), but still no luck.
- When we are trying to post this on email, only text is appearing in it, and when we tried posting it on whatsapp then only the image was visible.
- We are unable to post both together, can anyone suggest the proper way of doing it.
Thank you very much in advance.
Now your code gonna work due the new updates to whatsapp, before this didn't accept this kind of intent (ACTION_SEND_MULTIPLE) because it accepts only one file at a time.

Android: how to pre-populate an SMS message

I am writing an application that needs to pre-populate an SMS message with the first name of the contact when using the stock android SMS messenger.
For example if my contacts name is Alex Smith.
When I select Alex Smith to type a message to, I want the text box to already have
'Alex, '
at the beginning of the SMS.
Please how can I achieve that?
Fetch the contact name from contacts, and do like as follows:
String contactName = "Alex"; // get it from selected contact
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", contactName+"," );
startActivity( intent );
Just look over here:
Send SMS via intent
You use a Intent to send the SMS and attach some pre defined text via the EXTRA_TEXT attribute. Quite easy to do. And it works for the normal SHARE intent as well.
You can't change system apps, but you can send "share intent" from your app to SMS App. As you remember, when you push "share" button in some apps, you can share smth with SMS. (You'll have SMS with text that app put in intent). SO, put contact's name in "share intent" and send it to SMS app.
it's bit late, but i hope it will help future users.
void prePopulateSMS(final String mblNumVar, final String smsMsgVar) {
Log.d(TAG, "prePopulateSMS called. smsMsgVar: " + smsMsgVar);
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", mblNumVar);
smsIntent.putExtra("sms_body", smsMsgVar);
startActivity(smsIntent);
}

Problem with fill the sms body in Androids' default sms Acvtivity

I have a problem with opening a default sms Activity.
I'm using the code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"+contact));
intent.putExtra("sms_body", R.string.sms);
startActivity(intent);
It happens to fill the number but not body. Have you come across this problem? Or maybe you know other way to open default sms Activity with filled number and body?
EDIT
OK. What I found is that Android has problem with accessing the String in R file. What is the way to convert some R.string to String in code?
So there is a way. Sorry for being stupid
intent.putExtra("sms_body", getString(R.string.sms));

Categories

Resources