简体   繁体   English

如何从Android手机获取电话号码

[英]How to get phone number from android phone

How to get the phone number from an android phone. 如何从Android手机获取电话号码。 I have used this code but it doesn't get the current number. 我已经使用了这段代码,但是没有得到当前的号码。 It get the number that came with the phone, so if I change the SIM it gets the previous number. 它获取了手机随附的号码,因此,如果我更换SIM卡,它将获取先前的号码。

    TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String number = manager.getLine1Number();

This code gets a number but not the the current one. 此代码获取一个数字,但不是当前数字。 How would I get the current number. 我将如何获得当前号码。

try using this 尝试使用这个

TelephonyManager telemamanger = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String getSimSerialNumber = telemamanger.getSimSerialNumber();  

and use: 并使用:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Sim serial Number and sim number is unique. Sim序列号和sim编号是唯一的。 You can try this for get sim serial number and get sim number and Don't forget to add permission in manifest file. 您可以尝试此操作以获取SIM卡序列号和SIM卡号,并且不要忘记在清单文件中添加权限。

 TelephonyManager telemamanger = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

 String getSimSerialNumber = telemamanger.getSimSerialNumber();
 String getSimNumber = telemamanger.getLine1Number();

And add below permission into your Androidmanifest.xml file. 并将以下权限添加到您的Androidmanifest.xml文件中。

 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Note : it is only possible in single sim phone , if you try with dual sim phone then you not getting your phone number. 注意:仅在单SIM卡手机中才有可能,如果您在双SIM卡手机上尝试,则无法获取您的电话号码。

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

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