2014-06-17 83 views
0

大家好, 有什么方法可以检查android设备是否有SIM卡模块。我已经检查设备是否具有SIM或not.Using此代码检查设备是否有SIM卡模块

public void SimCheck() { 
    TelephonyManager telMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
    int simState = telMgr.getSimState(); 
    switch (simState) { 
    case TelephonyManager.SIM_STATE_ABSENT: 
     Log.d("SimCheck", "No sim Availble"); 
     Toast.makeText(getApplicationContext(), "No Sim Availble ", 
       Toast.LENGTH_LONG).show(); 
     break; 
    case TelephonyManager.SIM_STATE_READY: 
     Log.d("SimCheck", "Sim Is availble"); 
     Toast.makeText(getApplicationContext(), "Sim Is Availble", 
       Toast.LENGTH_LONG).show(); 
     break; 

    case TelephonyManager.SIM_STATE_UNKNOWN: 
     Log.d("SimCheck", "Network Locked"); 
     Toast.makeText(getApplicationContext(), 
       "Sim state unknown or network not Availble ", 
       Toast.LENGTH_LONG).show(); 
     break; 

    } 

} 

现在我要检查设备是否有它的SIM模块或没有(因为片没有在他们SIM选项)。需要帮忙。在此先感谢

+0

http://stackoverflow.com/a/8396069/2562861 – Shijil

回答

1

如果你希望你的应用程序需要SIM模块可以添加

<uses-feature android:name="android.hardware.telephony" 
       android:required="true"/> 

您menifest。

1

尝试:FEATURE_TELEPHONY

Added in API level 7 Feature for getSystemAvailableFeatures() and hasSystemFeature(String): The device has a telephony radio with data communication support.

PackageManager pm = this.getPackageManager(); 
boolean hasTelephony=pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); 

注:“这对检测短信功能,但如果设备已经安装谷歌语音,即使它没有电话功能任何问题,仍然可以发送短信,所以这种方式可能会给你带来错误的否定。“

还要检查https://stackoverflow.com/a/8129536/28557