1
public class MobileNumber extends Activity {

    TextView mobNO;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.mobile_number);
        mobNO = (TextView) findViewById(R.id.txtMobNO);

        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String getSimSerialNumber = tm.getSimSerialNumber();
        String getOperatorName = tm.getSimOperatorName();
        String getNetworkCountry = tm.getNetworkCountryIso();
        String getDeviceSoftVersion = tm.getDeviceSoftwareVersion();
        String getDeviceId = tm.getDeviceId();

        if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {

            String mPhoneNumber = tm.getLine1Number();

            String mobilenumber = mPhoneNumber.substring(Math.max(
                    mPhoneNumber.length() - 10, 0));

            Log.e("My Number is:-", "-------" + "  " + mobilenumber);
            Log.e("My Operator Name is:- ", "*******" + "  " + getOperatorName);
            Log.e("My Sim is:-", "******* " + "  " + getSimSerialNumber);
            Log.e("My Network Country is:-", "*******" + "  "
                    + getNetworkCountry);
            Log.e("My Device Software Version:-", "*******" + "  "
                    + getDeviceSoftVersion);
            Log.e("My Device Id is.:-", "-------" + "  " + getDeviceId);

            mobNO.setText(mobilenumber);

        } else {

            Log.e("no sim card", "...");

        }

    }

}

Output

--------------------------------------------OUTPUT----------------------------------------------------
09-08 14:17:24.618: E/My Number is:-(1206): -------
09-08 14:17:24.618: E/My Operator Name is:-(1206): *******  Android
09-08 14:17:24.618: E/My Sim is:-(1206): *******   89014103211118510720
09-08 14:17:24.618: E/My Network Country is:-(1206): *******  us
09-08 14:17:24.618: E/My Device Software Version:-(1206): *******  null
09-08 14:17:24.618: E/My Device Id is.:-(1206): -------  000000000000000
Ambrish
  • 3,627
  • 2
  • 27
  • 42
InsaneCat
  • 2,115
  • 5
  • 21
  • 40
  • Not all SIM cards provide the MSISDN number. http://stackoverflow.com/questions/2480288/how-can-i-programmatically-obtain-the-number-of-the-android-phone-with-the-api?lq=1 – laalto Sep 08 '14 at 09:37
  • so what can i do?? i'm put above code but can't get mobile number.. – InsaneCat Sep 08 '14 at 11:49
  • i'm tried different network provider sim cards. but just got blank. – InsaneCat Sep 08 '14 at 11:51
  • Yes, that's just how it works. – laalto Sep 08 '14 at 11:52
  • just got blank. i know above code is perfect but i dont know what's the problem.. :( – InsaneCat Sep 08 '14 at 12:07
  • in Short number only displaying in those cell phone whose display cell number in Setting/about phone/status/my mobile number then we can directly got a number from cell phone to application. – InsaneCat Oct 31 '14 at 12:41

0 Answers0