tags:

views:

205

answers:

2

this android aplication get mobile number to get the device only

A: 

Use TelephonyManager's getLine1Number() method:

// may be null if unknown
String phoneNumber = TelephonyManager.getDefault().getLine1Number();
fiXedd
thank you very much
narasimha
+3  A: 

You can use the TelephonyManager to do this:

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

The documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.

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.)

Dave Webb
thank you very much
narasimha
Important on SO, you have to mark accepted answers by using the tick on the left of the posted answer, below the voting. This will increase your rate.
Pentium10