开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜