简体   繁体   English

如何在Android中检测信号强度?

[英]How to detect signal strength in Android?

I want to send SMS when the signal strength is above 5 (I believe that is the minimum signal required to send an SMS). 我想在信号强度大于5时发送SMS(我相信这是发送SMS所需的最小信号)。 however, i want a reliable method to check this, so checking signal strength seems to be the best bet as it would also cover airplane mode. 但是,我希望有一种可靠的方法来进行检查,因此检查信号强度似乎是最好的选择,因为它也可以涵盖飞行模式。

An important constraint is that CellSignalStrength was added in API level 17, and need my code to work on API level 8 and above. 一个重要的约束是CellSignalStrength是在API级别17中添加的,需要我的代码才能在API级别8及更高版本上工作。

There is a thing - SignalStrength in android.telephony.SignalStrenght 有件事-android.telephony.SignalStrenght中的SignalStrength

The class contains methods to get various network strenght for example: getGsmSignalStrength() which gives you data in range 0-31 31 (99 is invalid) 该类包含获取各种网络getGsmSignalStrength()方法,例如: getGsmSignalStrength()可为您提供0-31 31范围内的数据(99无效)
For CDMA there are other methods like getCdmaDbm() which gives you values in dBm so you should convert them to your scale. 对于CDMA,还有其他方法,例如getCdmaDbm()可以为您提供以dBm为单位的值,因此您应该将其转换为比例。
[EDIT]Example of use [EDIT]使用示例

telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

final PhoneStateListener mListener = new PhoneStateListener() {
 @Override
 public void onSignalStrengthsChanged(SignalStrength sStrength) {
  //get your signals data
 }
};

// Register the listener for the telephony manager
telephonyManager.listen(mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

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

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