识别安卓平板电脑是否有sim卡插槽



有没有办法从我的应用程序中检查平板电脑是否有sim卡插槽?

我的要求是找出平板电脑是仅Wifi还是Wifi+蜂窝设备。我检查了Stack Overflow上提供的早期链接,它们似乎都不适用于我的设备。仅Wifi单元在网络信息下返回一个CCD_ 1。Wifi和蜂窝单元都返回CCD_ 2和CCD_。

在这两种情况下,返回的IMEI也是空的。如果sim卡插槽中插入了有效的sim卡,则我可以验证该单元是否为蜂窝单元,但如果蜂窝单元没有插入sim卡,或者sim卡插槽不好,则我无法区分蜂窝单元和wifi+蜂窝单元

试试这个代码:

TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);  //gets the current TelephonyManager
if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT){
  //the device has a sim card
} else {
  //no sim card available
}

您可以检查设备支持的网络接口。然后,您可以使用ConnectivityManager检查您的设备是否支持移动数据连接。

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
    if (cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
        // the device can use mobile networks
    }
}

最新更新