How to Send the Sms More Than 160 Character

How to send an SMS longer than 160 words without split up?

This is in short, impossible. Why? This is the global standard of the GSM which was created when the first phone was created. It is not within the power of the app to decide what limit of characters there can be in an SMS.

The character limit was already set decades ago...

Here is a brief piece on the reason why the SMS character limit is 160-140 characters....

So back in 1985 there was this guy named Friedhelm Hillebrand, who was
the chairman of the non-voice services committee within the Global
System for Mobile Communications (GSM), a group that sets standards
for the majority of the global mobile market. This guy had the task of
setting the limit on the amount of characters a text message could
contain.

To do this, Friedhelm sat at his typewriter, typing out random
sentences and questions on a sheet of paper to see what the average
amount of characters he used was. He found that each set of sentences,
ran just under 160 characters in length. That was good enough for him,
so he told his committee that text messages would be limited to 160
characters. Pretty scientific right?

Friedhelm’s methods didn’t sit well with the rest of the committee, as
they doubted a text message limited to 160 characters would be enough
space to prove a useful form of communication. So to calm their fears,
he backed up his assumption of limiting text messages to 160
characters by doing the following “market research”.

  1. Friedhelm took a bunch of postcards that he had received and found that often these postcards contained fewer than 150 characters. By
    this finding, he was being nice by offering consumers an additional 10
    characters.

  2. Friedhelm then analyzed a bunch of messages sent through Telex (a telegraphy network for business professionals). Even though these
    Telex transmissions didn’t have a limit on the amount of characters
    they were able to send, he found that on average the Telex messages
    were about the same length as the postcards.


So that’s why text messages are limited to 160 characters.

Hope this is enlightening.

How to send the SMS more than 160 character?

Junk characters? method sendMultipartTextMessage only send text message. If you want to send non text message, you should look to method sendDataMessage. Below is the code excerpt from android cts. It has example on how to send long messages.

SmsManager sm = SmsManager.getDefault();
ArrayList<String> parts =sm.divideMessage(LONG_TEXT);
int numParts = parts.size();

ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();

for (int i = 0; i < numParts; i++) {
sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
}

sm.sendMultiPartTextMessage(mDestAddr,null, parts, sentIntents, deliveryIntents)

Send SMS with more than 160 characters using Xamarin.Android

  • Changed characters for breaking the messages into parts from 160 to 150 (Not sure why it doesn't work for anything between 153-160)

Thanks Jason for the help

  • In the above code it was missing the last few characters because if you break the string in to parts there can be last part with less chars and not exactly 150. Changed the code and added a try and catch statement to get the all the characters in different parts
void TestButton_Click (object sender, System.EventArgs e)
{
string message = editTextTx.Text;

if (((decimal)message.Length/ 150) == message.Length / 150)
text_i = message.Length / 150;
else
text_i = (message.Length / 150) + 1;

Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
Android.App.AlertDialog alert = dialog.Create();
alert.SetTitle("Warning");
alert.SetMessage("It will need " + text_i.ToString() + " text message(s)");
alert.SetButton("OK", (c, ev) =>
{
var destinationAdd = "MY NUMBER";

SmsManager sm = SmsManager.Default;
if (message.Length >= 150)
{


//split the message into parts of 150 chars.


List<string> parts = new List<string>();

foreach (int i in Enumerable.Range(0, text_i))
{
string tword = "";
try
{
tword = message[(i * 150)..][..150];

}

catch (Exception ex) //to get the last few characters
{
tword = message[(i * 150)..];
}
parts.Add(tword);


};

sm.SendMultipartTextMessage(destinationAdd, null, parts, null, null);
}
else
{
sm.SendTextMessage(destinationAdd, null, message, null, null);
}
});
alert.Show();

}

Send SMS with more than 160 characters

You can split the string into chunks of certain length and use SendMultipartTextMessage to send the long text out. For example:

var content = "**HERE GOES SMS CONTENT**";
var destinationAdd = "**HERE GOES DESTINATION PHONE NUMBER**";

SmsManager sm = SmsManager.Default;
if (content.Length >= 150)
{
List<string> parts = new List<string>();
//split the string into chunks of 20 chars.
var enumerable = Enumerable.Range(0, content.Length / 20).Select(i => content.Substring(i * 20, 20));
parts = enumerable.ToList();
sm.SendMultipartTextMessage(destinationAdd, null, parts, null, null);
}
else
{
sm.SendTextMessage(destinationAdd, null, content, null, null);
}

Can't send more than 160 characters sms C# using GSM Modem

Alright, so after lots and lots of effort, research and minor change in the code i have got the solution and now it's working perfectly. I'm posting the solution that worked for me and I hope it will also help those who face the same problem.

Please make sure that the GSMCOMM library is up-to-date i.e. version
1.21.0 otherwise it may not work properly.

This is the correct code snippet. It will send short messages (i.e. less or equal to 160 chars) as well as long text message (i.e. more than 160 chars) as a single sms.

OutgoingSmsPdu[] pdus = null;
comm.Open();
pdus = SmartMessageFactory.CreateConcatTextMessage(message, number);
comm.SendMessages(pdus);
comm.Close();


Related Topics



Leave a reply



Submit