Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

how to get phone number from my app?  RSS feed

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
is it possible to retrieve my mobile number through my andriod app?
if so please suggest
 
Ranch Hand
Posts: 38
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code would do!. But be sure to insert Null Checks for the result.

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

Also insert the following permission in AndroidManifest file.

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 
Ranch Hand
Posts: 78
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I have used the same and in emulator it shows one 9 digit number . In android phone application crashes and shows "The application(process xxx.xxx.xxx) has stopped unexpectedly. please try again.


Any solution would be greatly appreciated.

Thanks,
 
Ranch Hand
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yeah, the one by Mohan Prasath will work. It would not work on an emulator because it does not support any sort of wireless connectivity. It would work on your phone
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!