Sending SMS with more than 160 characters as one message

yanie_143yanie_143 Member ✭✭
edited August 23 in Xamarin.Android

Good day!

Is there a way to send SMS with more than 160 characters as one message?

I tried the SendMultipartTextMessage but it will also send multiple messages.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited August 23

    I tried the SendMultipartTextMessage but it will also send multiple messages.

    SendMultipartTextMessage send multiple messages, but the recipient will receive a complete SMS.

    Split the string into chunks of certain length and use SendMultipartTextMessage to send the long text out.

    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);
    }
    

    Refer to:
    https://stackoverflow.com/questions/41719854/send-sms-with-more-than-160-characters

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    edited August 24
    * I guess splitting into 20 chars is just an example and 150 characters (or 160) should of course be used in real life? Who would like to send too many part messages? Or is there another reason?
    * If limit is 160 characters, why testing for more than 150 and not 160?
  • yanie_143yanie_143 Member ✭✭

    @Jarvan sorry for the late reply. I have tried that one but when my message was for example 200 characters long my recipient received 10 SMS when I split it into 20 characters. But when I tried splitting it into 100 characters, my recipient received 2 SMS. Im looking for something that can send SMS with more 160 characters as one message.

Sign In or Register to comment.