简体   繁体   English

检查手机是否可以发送短信

[英]Check if a phone can send SMS

I've already read some related question about it but most of them were targeting calls, not SMS. 我已经阅读了一些相关的问题,但大多数都是针对电话,而不是短信。 What I've found so far is: 到目前为止我发现的是:

TelephonyManager manager = (TelephonyManager) context
        .getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
    // I guess here are devices that are unable to send SMS
} else {
    // can send SMS
}

Is this true, devices with TelephonyManager.PHONE_TYPE_NONE are unable to send SMS? 这是真的,TelephonyManager.PHONE_TYPE_NONE的设备无法发送短信吗? I don't really understand the description of TelephonyManager.PHONE_TYPE_NONE, which is "No phone radio." 我真的不明白TelephonyManager.PHONE_TYPE_NONE的描述,这是“没有电话无线电”。

Thanks! 谢谢!

Yes with TelephonyManager.PHONE_TYPE_NONE you can't send SMS.As radio network is required to send SMS. 是的,使用TelephonyManager.PHONE_TYPE_NONE,您无法发送短信。由于无线电网络需要发送短信。 However you can use some IP based messengers like whats app, ebuddy on them 但是你可以使用一些基于IP的信使,比如whats app,ebuddy就可以了

if you see android.hardware.telephony (which you specify using uses-feature tag in Android manifest file), you will notice send/read/write SMS are mentioned under this feature. 如果您看到android.hardware.telephony (您在Android清单文件中使用uses-feature标签指定),您会注意到此功能下提到了发送/读/写SMS。

Galaxy TAB example,Can't make calls still phone type comes as PHONE_TYPE_CDMA , so adding additional check for line number will be required for such cases, as shown in above link Galaxy TAB示例,无法拨打电话仍然是电话类型来自PHONE_TYPE_CDMA ,因此在此类情况下需要添加额外的行号检查,如上面的链接所示

Use the following code: 使用以下代码:

Boolean canSendSMS (Context context)
{
PackageManager pm = context.getPackageManager();
return (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) || pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM