简体   繁体   English

如何获取双卡手机号码?

[英]How to Get the Dual Sim Mobile Number?

I want to get the mobile number from a different sim. 我想从其他SIM卡获取手机号码。 Dual sim number is saved in a different variable. 双SIM卡号码保存在其他变量中。

Some people give answer like: 有人给出如下答案:

TelephonyManager tm =(TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
String number = tm.getLine1Number();

I also give the permission in the Manifest file: 我还在清单文件中给予了许可:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

but it didn't work, all time number variable give ("") value. 但它不起作用,所有时间number变量都赋予(“”)值。 So please provide mw with a solution to this problem. 因此,请为MW提供此问题的解决方案。

If tm.getLine1Number() returns null or "" try to use tm.getSubscriberId() it always worked for me. 如果tm.getLine1Number()返回null或“”,请尝试使用tm.getSubscriberId()它总是对我tm.getSubscriberId()

String number = tm.getLine1Number();
if (number == null || number.equals("")) {
    number = tm.getSubscriberId();
}

Hope this helps. 希望这可以帮助。

You can do this through the Subscription Manager for minSdkVersion 22 onwards :) 您可以通过适用于minSdkVersion 22及更高版本的订阅管理器来完成此操作:)

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SubscriptionManager mSubscriptionManager = SubscriptionManager.from(getBaseContext());
        List<SubscriptionInfo> subscriptions = mSubscriptionManager.getActiveSubscriptionInfoList();


        for(SubscriptionInfo subscriptionInfo: subscriptions) {
            Log.v("SIM", subscriptionInfo.getNumber());
        }


    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM