1,一条SMS最大字符数

-----------------------------------------

android\frameworks\opt\telephony中

com.android.internal.telephony.gsm.SmsMessage
编码——>ENCODING_7BIT
/** The maximum number of payload septets per message */
public static final int MAX_USER_DATA_SEPTETS = 160; //单条信息160个字节(ASCII码对应的纯英文字符) /**
* The maximum number of payload septets per message if a user data header
* is present. This assumes the header only contains the
* CONCATENATED_8_BIT_REFERENCE element.
*/
public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153;//对于ASCII码对应的纯英文字符,长短信中每条短信的长度为153字节,7字节标记分页信息等协议 对于纯英文,1字符占用1字节
所以相当于第一条160个字符
第二条160-7-7=146个字符(第一条信息的协议信息也占用了第二条的长度)
第三条及以上,160-7=153个字符。
-----------------------------------------------------------------------
编码——>ENCODING_16BIT (处理包含中文等非ASSICC码字符的短信)
/** The maximum number of payload bytes per message */
public static final int MAX_USER_DATA_BYTES = 140;//单条信息140个字节(包含中文等非ASCII码字符的信息)

/**
* The maximum number of payload bytes per message if a user data header
* is present. This assumes the header only contains the
* CONCATENATED_8_BIT_REFERENCE element.
*/
public static final int MAX_USER_DATA_BYTES_WITH_HEADER = 134;//包含中文等非ASCII码字符的信息,长短信每条最大长度为140-6=134字节,6个字节用于标记分页信息 对于包含中文字符的信息,1字符占用2字节,140/2=70, 134/2=67, 6/2=3
所以相当于第一条70个字符
第二条70-3-3=64字符(第一条信息的分页信息也占用了第二条的长度)
第三条及以上70-3=67字符。
 
参考文档: 
长短信组织结构。UDH(user data header)
http://wenku.baidu.com/link?url=ksdB3TkIqKdm7tASZWqmZ8BJcUDbTbVw5FDWButs8pDlEM0ZuiJ7z36Z6lQDqZBA9vI-_XE1UWBvkRzQdeCY6wfK8labQsqIkZgQAZ7sZnK
2,SMS字符数达到多少会变成MMS

在MMS中可以配置达到多少条短信就转为彩信
ComposeMessageActivity中 updateCounter(.....)方法中有判断。
     if (!MmsConfig.getMultipartSmsEnabled()) {
// The provider doesn't support multi-part sms's so as soon as the user types
// an sms longer than one segment, we have to turn the message into an mms.
mWorkingMessage.setLengthRequiresMms(msgCount > 1, true);
} else {
int threshold = MmsConfig.getSmsToMmsTextThreshold(ComposeMessageActivity.this); //------ 这里定义了sms数量上限
mWorkingMessage.setLengthRequiresMms(threshold > 0 && msgCount > threshold, true);
}

MmsConfig中

public static int getSmsToMmsTextThreshold(Context context) {
int limitCount = context.getResources().getInteger(R.integer.limit_count); //先通过limit_count判断
if (limitCount != 0) {
return limitCount;
}
return mSmsToMmsTextThreshold; //如果limit_count=0,则用 mSmsToMmsTextThreshold判断
}
mSmsToMmsTextThreshold值定义
private static int mSmsToMmsTextThreshold = -1;
......
} else if ("smsToMmsTextThreshold".equalsIgnoreCase(value)) {
int maxSmstomms = context.getResources().getInteger(R.integer.config_max_smstomms);
mSmsToMmsTextThreshold = (maxSmstomms == 0) ? Integer.parseInt(text) : maxSmstomms;
}
信息中对于可以输入字符的数量并没有限制,如果不停的输入字符,数量达到上百条信息的字符数,对于内存较低的手机会出现卡顿现象。
那么我们做一个基本的限制,如40条信息的字符数作为上限
mTextEditorWatcher中增加对输入字符的数量判断
public void afterTextChanged(Editable s) {
//-----------------add by antoon
if(FEATURE_MMS_MESSAGE_COUNT_LIMIT){
int[] params=SmsMessage.calculateLength(mTextEditor.getText(), false);
int length = 0;
if(params[3]==SmsMessage.ENCODING_7BIT){
length = EN_ENCODE_MAX_LENGTH;
//modified by antoon
}else if(params[3] == SmsMessage.ENCODING_16BIT) {
//modified by antoon
length = CH_ENCODE_MAX_LENGTH;
}
if(mTextEditor.getText().length() > length) {
s = s.delete(length, s.length());
toast(R.string.textContentLimit);
}
}
//----------------end
}
private static final int EN_ENCODE_MAX_LENGTH = 3060*2;  // add by antoon
private static final int CH_ENCODE_MAX_LENGTH = 1340*2; //add by antoon
private static final boolean FEATURE_MMS_MESSAGE_COUNT_LIMIT=true; //add by antoon
05-04 02:27