[英]How can I check if a device supports SMS?
I want to disable SMS features programmatically on tablets without SIM card slot. 我想以编程方式在没有SIM卡插槽的平板电脑上禁用SMS功能。
I have tried this: 我已经试过了:
if (context.getSystemService(Context.TELEPHONY_SERVICE) != null)
{
// SMS features: enable
}
else
{
// SMS features: disable
}
but on my NVidia Shield Tablet K1 (without sim card slot) context.getSystemService(Context.TELEPHONY_SERVICE)
returns something and it looks like I have telephony service. 但是在我的NVidia Shield Tablet K1(不带SIM卡插槽)上, context.getSystemService(Context.TELEPHONY_SERVICE)
返回了一些信息,看起来我有电话服务。
What is wrong with my code? 我的代码有什么问题?
I would not assume that getSystemService()
to retrieve the TelephonyManager
would necessarily return null
in this case. 在这种情况下,我不认为用来检索TelephonyManager
getSystemService()
必须返回null
。
The official way to check for telephony is to call hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
on a PackageManager
, which you can get by calling getPackageManager()
. 检查电话官方的方法是调用hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
在PackageManager
,您可以通过调用get getPackageManager()
I have dusted off my NVIDIA Shield K1, and I get false
from hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
on that device. 我已经清除了NVIDIA Shield K1的灰尘,并且从该设备上的hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
获取false
信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.