Search code examples
androidsmsmanagerandroid-sms

Android smsManager handling Grave accent character


Struck some odd behaviour in my Android sms app when there is a Grave accent in the message, for example; smsTEXT = "Pls call the office asap if you`re keen."

Message is within single 160 char sms length, however when I call this;

ArrayList<String> segments = smsManager.divideMessage(smsTEXT);

the reported number of message parts is greater than 1, in fact 2

if (segments.size() > 1 ){
    smsManager.sendMultipartTextMessage(etc...)
    nSegments = segments.size();
} else {
    smsManager.sendTextMessage(etc...)
    nSegments = 1;
}

sendMultipartTextMessage appears to send the message perfectly well (with the Grave accent) in a single part anyway, while in all other respects the app works fine

If I substitute Grave accent with Apostrophe, only a single segment message is reported by size() and one sms sent in a single shot by sendTextMessage

If I put several Grave accents in the message, up to 4 segments are reported by size(), although it looks like sendMultipartTextMessage only sends one sms

Question: Is there something special about Grave accent in Android smsManager..?


Solution

  • Grave can't be represented by 7 bit ascii (the default for SMS). This then requires it to be sent as 16 bit characters, which reduces the maximum number of characters by half. Thus even a short message will require 2 SMSes. You'll see the same behavior with emojis and other non-ASCII characters. If you look at sending an SMS in a messaging app like Android's messages that shows the characters remaining in a text, you'll see as soon as you add a non-ASCII character it drops in half (or if placing it in the middle of a text, you'll see the number of texts leap up).