0

I am trying to get my telephone number programatically on Android. I have readen that always is not possible to get the number but perhaps somebody knows some solution to do this. Thank you. Here is my code:

    public class ReadSIM  extends Activity
{

    public void onCreate(Bundle savedInstance)
    {
        super.onCreate(savedInstance);
        setContentView(R.layout.main);

        TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        TextView mitexto =(TextView) findViewById(R.id.textView1);
        mitexto.setText(telemamanger.getLine1Number().toString());




    }
}

And here is the manifest permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
user3383415
  • 437
  • 1
  • 7
  • 22

2 Answers2

1

Ya it is not always possible to get Contact Number,because it mainly depends on sim card is it stores your number on your cell phone.

As per i know there is no other way to get Active Sim card number except this trick.

In place of that you can fetch IMSI number of that sim card.It is also unique.

And it is also available for developers.

Jay Vyas
  • 2,674
  • 5
  • 27
  • 58
0

Your code is correct. But not all the mobile phones returns you the telephone number. But in the most of the cases telemamanger.getLine1Number().toString() returns you an empty string.

simas
  • 222
  • 1
  • 8