大家好, 有没有办法检查Android设备是否有SIM模块。我已经检查过设备是否有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 :(得分:2)
你可以添加
<uses-feature android:name="android.hardware.telephony"
android:required="true"/>
如果您希望您的应用需要SIM模块,请到您的清单。
答案 1 :(得分:1)
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);
注意:“这对于检测短信功能存在问题。如果设备安装了Google语音,即使它没有任何电话功能,它仍然可以发送短信。所以这种方法可能会给你带来漏报。” / p>