Android Text Message count

Source: Internet
Author: User

I used to know that there is a limit of 70 characters for sending text messages, but I still don't know it when I use it. How many characters are there in Chinese and English? In the beginning, according to the old idea, two Chinese characters (two Chinese characters) and one English byte can be counted. up to 70 Chinese characters can be used to send 140 bytes, but errors always occur during sending. Later, I checked the text message code on the Internet to find out. Now I usually use the PDU mode to send text messages:

In PDU Mode, three encoding methods can be used to encode the sent content: 7-bit, 8-bit, and UCS2. 7-bit encoding is used to send Common ASCII characters. It encodes a string of 7-bit characters (the highest bit is 0) into 8-bit data, each 8 characters can be "COMPRESSED" into 7; 8-bit encoding is usually used to send data messages, such as slices and ringtones; while UCS2 encoding is used to send Unicode characters. The maximum size of the user information (TP-UD) segment of the PDU string is 140 bytes, so the maximum number of characters of short messages that can be sent in these three encoding modes is 160, 140, and 70, respectively. Here, an English letter, a Chinese character, and a Data byte are regarded as a character. It should be noted that the user information length (TP-UDL) of the PDU string has different meanings in various encoding methods. 7-bit encoding refers to the number of characters of the original Short Message, rather than the number of bytes After encoding. 8-bit encoding is the number of bytes. UCS2 encoding is also the number of bytes, which is twice the number of characters of the original short message.

Now I understand that the UCS2 encoding is used for sending text messages with Chinese characters. Both Chinese and English characters and space characters are counted as one character. A total of 70 messages are generated. An error occurs when more than one text message is sent. When a text message is sent in English, it uses 7-bit encoding to send 160 characters.

SmsManager has a divideMessage function that splits the strings into messages that can be sent according to the limits. I tried it and it could be used. However, when there is a Chinese character, the text message is 67 characters instead of 70, which may be related to the Lenovo testing machine I used. I do not know whether the host is normal on G1.

If there is still a url after the text message, it is not good to use divideMessage for mechanical splitting. To put the url in a separate text message, you still need to manually divide it.


Author: liujian885

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.