我正在使用Verizon的HTC Thunderbolt新LTE手持设备。在LTE网络下,我无法找到查询信号强度的API。通过进入测试模式(##4636##),我可以看到信号强度为-98dBm 2 asu。有人知道我可以使用哪个API来获取此信息吗?
我正在使用Verizon的HTC Thunderbolt新LTE手持设备。在LTE网络下,我无法找到查询信号强度的API。通过进入测试模式(##4636##),我可以看到信号强度为-98dBm 2 asu。有人知道我可以使用哪个API来获取此信息吗?
警告:此解决方案应适用于API17以下的Android系统。某些人可能在使用新的API或特定手机品牌(如华为)时遇到问题。
您需要使用此代码。实际上,您需要的所有信息都在这里:
String ssignal = signalStrength.toString();
String[] parts = ssignal.split(" ");
parts[]
数组将包含这些元素:part[0] = "Signalstrength:" _ignore this, it's just the title_
parts[1] = GsmSignalStrength
parts[2] = GsmBitErrorRate
parts[3] = CdmaDbm
parts[4] = CdmaEcio
parts[5] = EvdoDbm
parts[6] = EvdoEcio
parts[7] = EvdoSnr
parts[8] = LteSignalStrength
parts[9] = LteRsrp
parts[10] = LteRsrq
parts[11] = LteRssnr
parts[12] = LteCqi
parts[13] = gsm|lte|cdma
parts[14] = _not really sure what this number is_
那么,LTEdBm是什么:
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
int dbm = 0;
if ( tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE){
// For Lte SignalStrength: dbm = ASU - 140.
dbm = Integer.parseInt(parts[8])-140;
}
else{
// For GSM Signal Strength: dbm = (2*ASU)-113.
if (signalStrength.getGsmSignalStrength() != 99) {
int intdbm = -113 + 2
* signalStrength.getGsmSignalStrength();
dbm = Integer.toString(intdbm);
}
}
再见
SignalStrength
有一个getLevel
方法,返回一个从0到4的整数,表示信号强度。在一些其他LTE设备上(我不认为HTC Thunderbolt是其中之一),有一些方法,如getLteCqi
getLteRsrp
getLteRsrq
和getLteRssnr
,你需要自己确定如何使用这些值来计算信号强度。最后,我发现在一些设备上(我相信HTC Thunderbolt就是其中之一),LTE信号强度实际上是用标注为GSM信号强度的方法报告出来的!这太疯狂了,但却是真实的。欢迎下载“信号强度检测器”并在您的设备上查看结果和/或根据需要修改代码。setAccessible(true)
来忽略任何私有方法的问题。short_cid = long_cid / 0x100
- Tim S.import java.lang.reflect.Method;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;
public class MainActivity extends Activity
{
/*
* Some significant methods for LTE: getLteSignalStrength, getLteRssi,
* getLteRsrp and getRsrq. RSRP provides information about signal strength
* and RSSI helps in determining interference and noise information. RSRQ
* (Reference Signal Receive Quality) measurement and calculation is based
* on both RSRP and RSSI.
*/
private SignalStrength signalStrength;
private TelephonyManager telephonyManager;
private final static String LTE_TAG = "LTE_Tag";
private final static String LTE_SIGNAL_STRENGTH = "getLteSignalStrength";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Listener for the signal strength.
final PhoneStateListener mListener = new PhoneStateListener()
{
@Override
public void onSignalStrengthsChanged(SignalStrength sStrength)
{
signalStrength = sStrength;
getLTEsignalStrength();
}
};
// Register the listener for the telephony manager
telephonyManager.listen(mListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
private void getLTEsignalStrength()
{
try
{
Method[] methods = android.telephony.SignalStrength.class.getMethods();
for (Method mthd : methods)
{
if (mthd.getName().equals(LTE_SIGNAL_STRENGTH))
{
int LTEsignalStrength = (Integer) mthd.invoke(signalStrength, new Object[] {});
Log.i(LTE_TAG, "signalStrength = " + LTEsignalStrength);
return;
}
}
}
catch (Exception e)
{
Log.e(LTE_TAG, "Exception: " + e.toString());
}
}
}
signalStrength
的源头是什么? - CodeTower