开发者

How to find the mobile phone number in android?

I am developing a small android application in that i want find the mobile phone number used i开发者_Python百科n the particular phone

I tried the following

TelephonyManager tMgr =(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();

It is working fine in Emulator but It is not working in my phone

please help me anyone how to do that


You may want to look at this question, there is probably no better way, and you may need to ensure that your app has the READ_PHONE_STATE permission, but, your SIM may not be returning it.

I would be nervous about any phone trying to get this value. Why do you need it, there may be a better way to do what you want.

Programmatically obtain the phone number of the Android phone


the most simple way to know automatically a phone's number is to write an app to send a SMS. I use IMEI and some content to automatically capture the phone's number. I have a small SMS server and use it to update the DB. Asking phone number to a user is not realiable... The Imei is simple to obtain and combining to phone number is the right choice!


I disagree with all the answers here. Since practically these api's dont work consistently. So if your app is heavily dependent on the phone number, you must ask for it. Be prepared to ask for this work around manually, just incase you dont get the number.

Samsung phones for example are inconsistent with their API's across their phones. Some phones work and some dont. As compared to HTC or LG they are more consistent with their API's since they dont fiddle with the lower layer at all.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜