SMSManger not sending message with apostrophe in it - android

I am using this code to send messages:
private void sendSMS(String phoneNumber, String message) {
Log.d("phoneNumber", phoneNumber);
Log.d("Message", message);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, new Intent(
mContext, Object.class), 0);
smsManager.sendTextMessage(phoneNumber, null, message, pi, null);
}
It is not sending the messages with apostrophe. Here are the messages I tested:
Sorry, busy right now with a live person. I’ll contact you when I’m free.
Sorry, busy right now with a live person. I will contact you when I am free.
'
1 and 3 didn;t worked. But 2 worked. (yes... I sent only apostrophe in 3rd sms). Pretty weird. Any ideas?

If you want to send Apostrophe in SMS you have to use the escape character for an apostrophe. Putting a backslash character followed by a quote ( \" or \' ) will work.
In this case, your string should look like this "Sorry, busy right now with a live person. I\'ll contact you when I\'m free."

Related

Send text and image in same message using SmsManager in android

I am working on an application which is sending text and image messages. I am sending Text and Image using SmsManager in my Application as below. The problem is, this is sending separate messages for every image and text I am sending thus not getting in exact order, but I want to send and get message in exact order.
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
NewLeaveItemActivity.this, 0, new Intent(ACTION_MMS_SENT), 0);
SmsManager.getDefault().sendMultimediaMessage(getApplicationContext(),
mainImageContentUri, null, null,
pendingIntent);
SmsManager.getDefault().sendMultimediaMessage(getApplicationContext(),
qRCodeContentUri, null, null,
pendingIntent);
SmsManager.getDefault().sendMultimediaMessage(getApplicationContext(),
storeContentUri, null, null,
pendingIntent);
PendingIntent intent = PendingIntent.getBroadcast(
NewLeaveItemActivity.this, 0, new Intent(ACTION_MMS_RECEIVED), 0);
SmsManager.getDefault().sendTextMessage(mEditMobileNew.getText().toString().trim(), null, bellowMessage, pendingIntent, intent);
It wouldn't be a professional or better way to split the MMS into 2 or 3 parts and send them separately. There would be a better way so that we can control what order they are received in?
Please help me.
use this amazing library to send media through sms
https://github.com/klinker41/android-smsmms
Create one large mms message. Convert all sms into mms too.
Api will automatically divide into multiple mms and will be in order.
Don't use SMS all messages should be part of a big mms.
method used here
divideMessage
Added in API level 4
public ArrayList<String> divideMessage (String text)
Divide a message text into several fragments, none bigger than the maximum SMS message size
.
sendMultipartTextMessage
Added in API level 4
public void sendMultipartTextMessage (String destinationAddress,
String scAddress,
ArrayList<String> parts,
ArrayList<PendingIntent> sentIntents,
ArrayList<PendingIntent> deliveryIntents)
Send a multi-part text based SMS. The callee should have already divided the message into correctly sized parts by calling divideMessage.

SMS sending to multiple numbers not being sent

I am sending an SMS to multiple numbers. When I choose only one, it works, and the message is being sent immediately. But when I use multiple (3 for example) SMS Intent is opened, but after I click Send button I see "Sending..." message all the time, SMS is not sent.
Intent sms = new Intent(Intent.ACTION_VIEW);
sms.setType("vnd.android-dir/mms-sms");
sms.putExtra("address", getSMSNumbers);
sms.putExtra("sms_body", "Help!!!");
startActivity(sms);
And getSMSNumbers String looks like this: 512991220;505202222;606123456.
What is wrong? Why isn't the message being sent and it's "sending" all the time?
Also I see when I have more than 1 number, it's being converted to MMS - why?
Maybe you could loop through the numbers and send messages one by one, like this
android.telephony.SmsManager.getDefault().
sendTextMessage("00112233", null, "Message body text", null, null);
I managed to do this - needed to turn off "Group Messaging" in AVD Settings. App was trying to send MMS and that's why it wasn't being sent.

Sending long (concatenated) SMS in Japan

Is there anyone from Japan ? I have a question about Japan mobile network operators (Docomo, AU) and their phones: are they able to send/receive a long SMS (longer than 160 latin characters / 70 japanese characters)? or they are splitting the SMS in two fragments sent separately?
In my app, I want to send a long SMS using SMSManager's sendMultiPartTextMessage and I want to know if I can use it or send multiple SMS fragments using just sendTextMessage.
Thank you!
As per documentation, that's how you can send multi-parts message:
final String phoneNumber = "1111111111";
final String message = "this is text body for multi part sms...bla bla bla...";
SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(message);
sms.sendMultipartTextMessage(phoneNumber, null, parts, null, null);

sendTextMessage(phoneNumber, null, message, null, null); always returns success even when message not sent

I tried sms activity using this link
but the problem is that it always gives "message sent"
how to know if the message is really sent!
here is code
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
//...
}
In the mentioned link, there is no PendingIntent set for deliveryIntent or sentIntent in order to receive the status of message you need to send PendingIntent. See this link
I also faced similar NPE scenario but problem at my end was due to wrong phone number.
So you must also check if phone number was correct or not.

Unable to send text messages on some Android Phones using SmsManager

My mobile app occasionally is sending text messages, everything works great on most phones but i am starting to receive emails from some users stating the messages aren't going out. Here is the code i am using:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("+12223334444", null, "test sms", null, null);
I've read somewhere that I should use the PendingIntent, so i tried it as follows:
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0);
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, message, sentPI, deliveredPI);
So far I have gotten emails from users of Samsung Galaxy S II, Sprint Evo Shift, Samsung Sidekick phones.
Please keep in mind it's not phone specific, i have tested the app on two of these phones (my friends) and the text message was sent normally
The problem here is that you aren't handling retries at all. It is possible for the SMS to fail to send in a variety of colourful ways. You can listen for these events using the sent PendingIntent using something like:
public void onReceive(Context context, Intent intent) {
if (getResultCode() != Activity.RESULT_OK) {
// failed to send the sms, see SmsManager.ERROR_<description> for more info on why
}
}
What I suspect is happening is that users have no signal at the time you send the message, so it fails and never retries. This would also explain why it isn't device specific.

Categories

Resources