How to get a mobile number for my application using an API?
How do get the mobile number from an Android application? After 开发者_运维百科installing the application on the mobile, I want to get the mobile number of the phone. Is there any API available in Android?
From my experience, this has been the simplest method:
TelephonyManager manager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = manager.getLine1Number();
And then add this to your AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
See http://developer.android.com/reference/android/telephony/TelephonyManager.html#getLine1Number%28%29: you will probably need the appropriate permissions to get it.
精彩评论