如何检查设备是否支持SMS?

时间:2017-12-07 15:57:47

标签: android sms

我想在没有SIM卡插槽的平板电脑上以编程方式禁用短信功能。

我试过这个:

if (context.getSystemService(Context.TELEPHONY_SERVICE) != null)
{
    // SMS features: enable
}
else
{
    // SMS features: disable
}

但是在我的NVidia Shield平板电脑上K1(没有SIM卡插槽)context.getSystemService(Context.TELEPHONY_SERVICE)会返回一些东西,看起来我有电话服务。

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:2)

在这种情况下,我不认为getSystemService()检索TelephonyManager必然会返回null

检查电话的官方方法是拨打hasSystemFeature(PackageManager.FEATURE_TELEPHONY)上的PackageManager,您可以致电getPackageManager()获取。

我已经把我的NVIDIA Shield K1掸掉了,我从该设备上false获得了hasSystemFeature(PackageManager.FEATURE_TELEPHONY)

相关问题