简体   繁体   English

Android设备电话号码

[英]Android device telephone number

I am using the below method to get the phone number of my device 我正在使用以下方法获取设备的电话号码



    private void getMyNumber()
            { 

        // read_phone_State permission is specified
            String ph_num ="";
            TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); 
                    ph_num = telephonyManager.getLine1Number(); // returning null 
                    ph_num = telephonyManager.getSimSerialNumber(); // returning sim serial number
                    ph_num = telephonyManager.getSubscriberId(); // returning id 
                    ph_num = telephonyManager.getVoiceMailNumber(); // returning null
            }

Any ideas ... how to get the phone number 任何想法...如何获取电话号码

There is no 100% reliable way to get the phone number since whether or not the telephonyManager has access to it is dependent on the provider and how they encode the data on the SIM (for GSM phones, at least). 没有100%可靠的方法来获取电话号码,因为telephonyManager是否可以访问它取决于提供商以及提供商如何对SIM卡上的数据进行编码(至少对于GSM电话)。 If you want the phone number to uniquely identify the phone, use telephonyManager.getDeviceId() otherwise you may have to prompt the user for it. 如果您希望电话号码唯一地标识电话,请使用telephonyManager.getDeviceId()否则可能需要提示用户输入电话。

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

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