开发者

How to get your own phone number in Android

I am trying to develop an application that needs the phone number of SIM Card every time a new SIM Card is inserted in the phone....Then i will use that phone number to get the user subscribed to an online server.I have read many forums and found something like this

TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);

mPhoneNumber = tMgr.getLine1Number();

but everyone said that this is not an efficient method.If this is not an efficient method then which is the efficient method and also I cannot use any other propert开发者_运维知识库y like SIM id or Subscriber ID etc.I only need the PHONE NUMBER. Any help would be appreciated.


As far as I know, this method would not always return right SIM number; it depends on the SIM card itself. If you really want to get the SIM number, you can send a SMS to a specific phone, so you will get it.


TelephonyManager is not the right Solution,Because in some cases the number is not stored in the SIM, Due to my suggestion,You should use Shared Preference to store user's Phone number first time the application is open, and after that the number will used whenever you need in application. Thank you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜