40-Android之Mms在雙卡時每條資訊顯示卡號

liumengluo發表於2020-11-16

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;
}

相關文章