获取设备的电话号码
我正在制作一个应用程序,其中我必须获取 GSM 设备的手机号码,我使用以下代码在 TextView 中显示电话号码,但一切都是徒劳的。谁能帮我做到这一点。
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String number = mTelephonyMgr.getLine1Number();
Phoneno=(TextView)findViewById(R.id.Phoneno);
Phoneno.setText(number);
I am making an app in which I have to get the mobile number of the GSM device and I used the following code to show to phone no in a TextView, but all in vain. Can anyone help me do this.
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String number = mTelephonyMgr.getLine1Number();
Phoneno=(TextView)findViewById(R.id.Phoneno);
Phoneno.setText(number);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您在清单中需要权限READ_PHONE_STATE
希望这个会帮助你
make sure you Requires permission READ_PHONE_STATE in manifest
Hope This will help you
查看这个例子,它将帮助您找出问题所在。
Check this example, it will help you to find out the issue.
TelephonyManager.getLine1Number() 是迄今为止唯一可用的解决方案。实际上 sim 不包含有关号码的信息。它仅由网络传递。这也是 sim 相关的。对于某些设备,它 (TelephonyManager.getLine1Number()) 可以工作.对于某些人来说可能不是。
TelephonyManager.getLine1Number() is the only solution available till now.Actually sim does not contains info about the number .It is delivered by the network only.Also this is sim dependent .For some device it (TelephonyManager.getLine1Number()) will work.For some it may not.