How to get Owner/sim number and Network Mode

后端 未结 4 1692
野的像风
野的像风 2021-01-15 17:01

I want to get the SIM number which currently in the phone i.e. owner number. and network mode whether it is GSM or CDMA.

I search on net and try to do this by getLin

相关标签:
4条回答
  • 2021-01-15 17:30

    to get the number of ur SIM CARD , and the network u can do this :

    TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    
        ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
            if(cm.getActiveNetworkInfo().getTypeName().equals("MOBILE"))
                network = "cellnetwork/3G";
            else if(cm.getActiveNetworkInfo().getTypeName().equals("WIFI"))
                network = "wifi";
            else 
                network ="na";
    
        uphone = tm.getLine1Number();
    

    hope it hepls :)

    i've tried it , and it works for me

    0 讨论(0)
  • 2021-01-15 17:48

    This question had been asked many times on SO.

    See How to get the mobile number of current sim card in real device?

    And, I must add that getting the phone number depends on whether the carrier provided it on the SIM card or not.

    0 讨论(0)
  • 2021-01-15 17:51

    To get the phone number, try the TelephonyManager.

    If that does not work you can get this info through AccountManager. One of the accounts will be the number.

    See source details implementation on this post: TelephonyManager.getLine1Number() failing?

    0 讨论(0)
  • 2021-01-15 17:53

    For the phone number you can do,

    // Get the phone number from the telephony manager, and display it
    TelephonyManager info = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    String phoneNumber = info.getLine1Number();
    

    For the network mode, see TelephonyManager

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