-3

This my code but not working

tManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

EditText e3 = (EditText) findViewById(R.id.phno);
           e3.setText(tManager.getLine1Number());
Brijesh Kumar
  • 1,685
  • 2
  • 17
  • 28
S.BM
  • 71
  • 1
  • 1
  • 3
  • It is not work in above API 14. – D.J Oct 18 '16 at 05:18
  • Try checking in Phone--> Settings --> About --> Phone Identity, If you are able to view the Number there, the probability of getting the phone number from above code is higher. If you are not able to view the phone number in the settings, then you won't be able to get via this code! – Priyank Patel Oct 18 '16 at 05:42

1 Answers1

1

This is working fine for me

Inside onCreate

   Button btnSubmit = (Button) findViewById(R.id.buttonLogin);
            btnSubmit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    TelephonyManager telephonyManager = (TelephonyManager)
                            getSystemService(Context.TELEPHONY_SERVICE);
                    String CountryISO = telephonyManager.getSimCountryIso().toString().toUpperCase();
                    String getSimSerialNumber = telephonyManager.getSimSerialNumber();
                    String getSimNumber = telephonyManager.getLine1Number();


                    Log.e("Telephone Data : "getSimSerialNumber + "  " + getSimNumber);
                }
            });

Dont forget to add permission in manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Rissmon Suresh
  • 13,173
  • 5
  • 29
  • 38