android 获取sim一些信息方法如下:

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weicaihui2008/article/details/51461623
  1. 获取服务提供商名字SPN(Returns the Service Provider Name)

    (1)获取默认SPN:

        TelephonyManager tm = (TelephonyManager)Context.getSystemService(Context.TELEPHONY_SERVICE);
        String SPN = tm.getSimOperatorName()
    

    (2)获取双卡SPN方法:

    //spn
    private String getSimOperatorName(SubscriptionInfo sir) {
        if (sir == null) {
            return null;
        }
        return getSimOperatorName(sir.getSubscriptionId());
    }
    
    private String getSimOperatorName(int subId) {
        String simOperatorName = null;
    
        try {
            Method method = TelephonyManager.class.getDeclaredMethod("getSimOperatorNameForSubscription", int.class);
    
            simOperatorName = (String) method.invoke(mTelephonyManager, subId);
        } catch (Exception e) {
        // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return simOperatorName;
    }
    
  2. 获取国际移动用户识别码(IMSI:International Mobile Subscriber Identification Number):
    (1)获取默认的IMSI:

        String  IMSI = tm.getSubscriberId();
    

    (2)获取双卡的IMSI:

    //imsi
    private String getSubscriberId(SubscriptionInfo sir) {
        if (sir == null) {
            return null;
        }
        return getSubscriberId(sir.getSubscriptionId());
    }
    
    //获取imsi
    private String getSubscriberId(int subId) {
        String subscriberId = null;
    
        try {
            Method method = TelephonyManager.class.getDeclaredMethod("getSubscriberId", int.class);
    
            subscriberId = (String) method.invoke(mTelephonyManager, subId);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return subscriberId;
    }
    
  3. 下载apk

猜你喜欢

转载自blog.csdn.net/weicaihui2008/article/details/51461623
今日推荐