40-Android之Mms在双卡时每条信息显示卡号
平台: MTK6739 Android10
双卡时, 客户要求会话里面的信息都需要显示卡号.
考虑在每条信息后面添加.
packages/apps/Mms/src/com/android/mms/ui/MessageListItem.java
private CharSequence formatMessage(MessageItem msgItem, String body, String subject, Pattern highlight, String contentType) {
SpannableStringBuilder buf = new SpannableStringBuilder();
boolean hasSubject = !TextUtils.isEmpty(subject);
if (hasSubject) {
buf.append(mContext.getResources().getString(R.string.inline_subject, subject));
}
if (!TextUtils.isEmpty(body)) {
// Converts html to spannable if MmsContentType is "text/html".
if (contentType != null && MmsContentType.TEXT_HTML.equals(contentType)) {
buf.append("\n");
buf.append(Html.fromHtml(body));
} else {
if (hasSubject) {
buf.append(" - ");
}
buf.append(body);
}
}
// 修改此处 begin @{
// 之前直接用过subId, 但是出现不同机器上显示不同的subId,
// 由于代码默认是支持4张卡的, 导致有些显示1/2, 2/3, 1/3等
int subId = msgItem.getSubId();
SubscriptionManager subscriptionManager = (SubscriptionManager) mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
if(subscriptionManager.getActiveSubscriptionInfo(subId) != null) {
int simSlotIndex = subscriptionManager.getActiveSubscriptionInfo(subId).getSimSlotIndex();
String simCard = mContext.getResources().getString(R.string.card) + (simSlotIndex + 1);
buf.append(" ").append(simCard);
}
// }@ end
// add for ipmessage
buf = new SpannableStringBuilder(IpMessageUtils.formatIpMessage(body, true, buf));
if (highlight != null) {
Matcher m = highlight.matcher(buf.toString());
while (m.find()) {
buf.setSpan(new StyleSpan(Typeface.BOLD), m.start(), m.end(), 0);
}
}
buf.setSpan(mLeadingMarginSpan, 0, buf.length(), 0);
return buf;
}