Android : SMS Text Message couning

on Saturday, September 27, 2014


for counting sms length i saw this algorithm(Ask) :


i convert it to java in this form :



String text =EtMsMessage.getText().toString();
Boolean ucs2=false;

for (char character : text.toCharArray())
{
if (character >= 0x600 && character <= 0x6ff)
ucs2=true;
if (character >= 0x750 && character <= 0x77f)
ucs2=true;
if (character >= 0xfb50 && character <= 0xfc3f)
ucs2=true;
if (character >= 0xfe70 && character <= 0xfefc)
ucs2=true;
}

int unitLength=ucs2 ? 70 : 160;


if (text.length > unitLength)
{
if (ucs2)
unitLength = unitLength - 4;
else
unitLength = unitLength - 8;
}
intcount = (int)Math.max(Math.ceil(text.length / unitLength), 1);

TvMS.setText("("+Integer.toString(count)+")"+Integer.toString(unitLength * count - text.length));


but it not return correct value:


i tried too ways to counting SMS lenght , but not work right any way.


what i should to do for counting sms in ucs2 form?


0 comments:

Post a Comment