-1

Simply, I want to retrieve Mobile Number and show it to textView in android Studio?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    tm.getLine1Number();


}
Mukkaram Ali
  • 3
  • 1
  • 2

1 Answers1

0

Make sure you have this permission in your manifest

<uses-permission android:name="android.permission.READ_PHONE_STATE"/> '

Then use this code to put the number in a TextView

TextView phone = (TextView) findViewById(R.id.phoneNumber);
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
phone.setText(tm.getLine1Number());

Of course, make sure that your layout activity_main has a textview with the ID phoneNumber, or whatever you want to use.

Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
  • where to permisssion implement and how to able show number i=on screen.. i m unable get your point please guide me .. thanx! – Mukkaram Ali Oct 06 '15 at 08:23
  • The permission should go inside `AndroidManifest.xml` inside the `` tag. I'm not sure what you mean by the second part of your question – Andrew Brooke Oct 06 '15 at 13:57