[ACCEPTED]-How to get LTE signal strength in Android?-signal-strength
Warning : this solution should work for Android below API17. Some people may have troubles with newer api or specific phone brand (like Huawei)
You need to use this code. In fact, all 3 the information you need is here :
String ssignal = signalStrength.toString();
String[] parts = ssignal.split(" ");
The parts[]
array 2 will then contain these elements:
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_
So, LTEdBm 1 is :
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);
}
}
bye
In order to solve this question I created 25 an application called Signal Strength Detector 24 and with source code on GitHub. In my past experience, some 23 devices running Android ICS 4.0 and up have 22 a getLevel
method on SignalStrength
that returns an integer from 21 0 - 4 reporting the signal strength. On 20 some other LTE devices (I do not believe 19 the HTC Thunderbolt), there are some methods 18 like getLteCqi
getLteRsrp
getLteRsrq
and getLteRssnr
which I will leave to you to 17 determine how to use these values to calculate 16 a signal strength. Finally, I found that 15 on some devices (I believe the HTC Thunderbolt) the 14 LTE signal strength is actually reported 13 with the methods labelled for GSM signal 12 strength! It's crazy, but true. Feel free 11 to download Signal Strength Detector and 10 check out the results on your device and/ or 9 modify code as necessary.
As a side note, you 8 will need to use Reflection to access these 7 methods, again which I will leave to you 6 to determine how to best implement this. It's 5 fairly simple, but you need to do a lot 4 of try-catch to determine if the method 3 is present, and sometimes setAccessible(true)
just to ignore 2 any issues with private methods.
Hope this 1 helps!
This is complete working implementation 2 of a sample app which uses a reflection 1 to get LTE signal strength:
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());
}
}
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.