简体   繁体   English

如何在 Android 中获取自己的电话号码

[英]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我正在尝试开发一个应用程序,每次将新 SIM 卡插入手机时都需要 SIM 卡的电话号码....然后我将使用该电话号码让用户订阅在线服务器。我已阅读很多论坛,发现了这样的东西

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 property like SIM id or Subscriber ID etc.I only need the PHONE NUMBER.但是每个人都说这不是一种有效的方法。如果这不是一种有效的方法,那么这是一种有效的方法,而且我不能使用任何其他属性,如 SIM id 或 Subscriber ID 等。我只需要电话号码。 Any help would be appreciated.任何帮助,将不胜感激。

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. TelephonyManager 不是正确的解决方案,因为在某些情况下,号码没有存储在 SIM 卡中,由于我的建议,您应该在第一次打开应用程序时使用共享偏好来存储用户的电话号码,之后该号码将在任何时候使用您需要在应用程序中。 Thank you.谢谢你。

As far as I know, this method would not always return right SIM number;据我所知,这种方法并不总是返回正确的 SIM 号码; it depends on the SIM card itself.这取决于 SIM 卡本身。 If you really want to get the SIM number, you can send a SMS to a specific phone, so you will get it.如果你真的想得到 SIM 号码,你可以向特定的手机发送一条短信,这样你就会得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM