Util.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:android-protwall 作者:
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    if (!hasPhoneStatePermission(context))
        return "No permission";

    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append("Slots ")
            .append(sm.getActiveSubscriptionInfoCount())
            .append('/')
            .append(sm.getActiveSubscriptionInfoCountMax())
            .append("\r\n");

    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null)
        for (SubscriptionInfo si : subscriptions)
            sb.append("SIM ")
                    .append(si.getSimSlotIndex() + 1)
                    .append('/')
                    .append(si.getSubscriptionId())
                    .append(' ')
                    .append(si.getCountryIso())
                    .append('/')
                    .append(si.getMcc()).append(si.getMnc())
                    .append(' ')
                    .append(si.getCarrierName())
                    .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append("\r\n");

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号