HTC Thunderbolt の Verizon の新しい LTE ハンドセットを使用しています。ハンドセットが LTE の場合、信号強度を照会する API が見つかりません。フィールド テスト モード ( # #4636# # ) に入ると、信号強度が -98dBm 2 asu と表示されます。この情報を取得するために使用できる API を知っている人はいますか?
4 に答える
In order to solve this question I created an application called Signal Strength Detector and with source code on GitHub. In my past experience, some devices running Android ICS 4.0 and up have a getLevel
method on SignalStrength
that returns an integer from 0 - 4 reporting the signal strength. On some other LTE devices (I do not believe the HTC Thunderbolt), there are some methods like getLteCqi
getLteRsrp
getLteRsrq
and getLteRssnr
which I will leave to you to determine how to use these values to calculate a signal strength. Finally, I found that on some devices (I believe the HTC Thunderbolt) the LTE signal strength is actually reported with the methods labelled for GSM signal strength! It's crazy, but true. Feel free to download Signal Strength Detector and check out the results on your device and/ or modify code as necessary.
As a side note, you will need to use Reflection to access these methods, again which I will leave to you to determine how to best implement this. It's fairly simple, but you need to do a lot of try-catch to determine if the method is present, and sometimes setAccessible(true)
just to ignore any issues with private methods.
Hope this helps!
これは、反射を使用して LTE 信号強度を取得するサンプル アプリの完全な実装です。
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());
}
}
}
PhoneStateListenerをLISTEN_SIGNAL_STRENGTHSに登録する必要があります。次に、現在の信号強度を含むコールバックと、更新を含む将来のコールバックを取得します。