Android获取电话SIM号码

时间:2012-11-05 11:46:52

标签: android

如何使用代码获取SIM卡号码? 我尝试了这段代码并且没有返回任何数字

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

3 个答案:

答案 0 :(得分:2)

使用

TelephonyManager phoneManager = (TelephonyManager) 
getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = phoneManager.getLine1Number();

需要READ_PHONE_STATE权限。

答案 1 :(得分:0)

请尝试以下代码:

    TelephonyManager mTelephonyMgr =
    (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

    String sDeviceID = mTelephonyMgr.getDeviceId();
    String sSimSerial = mTelephonyMgr.getSimSerialNumber(); 
String sSimlineNumber = mTelephonyMgr.getLine1Number(); 

设置以下权限

android.permission.READ_PHONE_STATE in Android Manifest file

答案 2 :(得分:0)

试试这样..

TelephonyManager telphMgr =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);

String simSerialNumber = telphMgr.getSimSerialNumber();

参考:

http://developer.android.com/reference/android/telephony/TelephonyManager.html#getSimSerialNumber%28%29