to get phone number programmatically in Android

前端 未结 4 2049
耶瑟儿~
耶瑟儿~ 2020-12-01 16:51

I am using the code

TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
  mPhoneNumber = tMgr.getLine1Number(         


        
相关标签:
4条回答
  • 2020-12-01 17:18

    Look for TelephonyManager.getSubscriberId(), this will give the unique id for each SIM.

    0 讨论(0)
  • 2020-12-01 17:22

    This is a known issue. Many SIM across the globe would return null. You should rather use IMEI number however even that can return null.

    TelephonyManager.getDeviceId()
    
    0 讨论(0)
  • 2020-12-01 17:23

    I think Sim serial Number is unique. You can try this.

    TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String getSimSerialNumber = telemamanger.getSimSerialNumber();
    

    Let me know if there is any issue.

    0 讨论(0)
  • 2020-12-01 17:37

    With API Level greater than or equal to 22 : You can access all the SIM details using SubscritionManager. Use following command to list all Sim numbers(Works well for Dual Sim also):

    List<SubscriptionInfo> list = SubscriptionManager.from(getApplicationContext()).getActiveSubscriptionInfoList();
    for(SubscriptionInfo s : list){
       Log.d("SIMMANAGER",s.getNumber());
    }
    

    Note : This only works well when the operator stored their mobile number in sim card. Else, this method returns null.

    0 讨论(0)
提交回复
热议问题