Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

android how to obtain the phone number of the machine through the interface?

 
Regen Mark
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
android how to obtain the phone number of the machine through the interface?
anyone can help me?
 
Mohan Prasath
Ranch Hand
Posts: 38
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of the time the following code would return null or your old SIM number. But it works some times

String phoneNo = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getLine1Number();

You have to give the following permission in the AndroidManifest <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic