Andy Flower
Andy Flower

Reputation: 3

Capture mobile number of application User

Is there a way such that the smart phone application will be able to fetch mobile number that is currently active in it. Is it something feasible?

Upvotes: 0

Views: 1106

Answers (1)

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

You can use the TelephonyManager to do this:

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

You'll need to give your application permission to make this query by adding the following to your Manifest:

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

(You shouldn't use TelephonyManager.getDefault() to get the TelephonyManager as that is a private undocumented API call and may change in future.)

Upvotes: 1

Related Questions