How to get LTE signal strength in Android?
Asked Answered
C

4

15

I am using Verizon's new LTE handset from HTC Thunderbolt. I cannot find the API to query for the signal strength while the handset is on LTE. By entering the field test mode (##4636##), I can see signal strength as -98dBm 2 asu. Anyone know what API I could use to get this info?

Cyprian answered 4/4, 2011 at 22:25 Comment(0)
C
16

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 the information you need is here :

String ssignal = signalStrength.toString();

String[] parts = ssignal.split(" ");

The parts[] array 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 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

Cranky answered 6/5, 2013 at 9:39 Comment(12)
From where does signalStrength origin?Yarrow
I'm not sure (it was a few mouths ago) but I think it comes from a SignalStrength Object : [link]developer.android.com/reference/android/telephony/… [code] public void onSignalStrengthsChanged(SignalStrength signalStrength) { super.onSignalStrengthsChanged(signalStrength);}[/code]Cranky
This is an interesting solution, but the SignalStrength implementation is not consistent on all devices and is not always reported in that order/ with those values.Mweru
Thanks Tom. Yes, this is not consistent, but it's the only solution I find to do this. If I remember, some device dont set all value. Maybe 4G is too recent.... Do you have an other solution ?Cranky
Good, it seens to be correct. But one question: where did you found this info? Can you lend the references?Anders
A guy made an app like this and post an article in his blog to show how he did, So his documentation helps me to do my application. But I can't find the link now. Maybe the guy deleted his websiteCranky
First of all thanks for sharing your approach! I think the last line isn't correct because dbm is of type int not string. Moreover since API level 17 there exists CellSignalStrengthLteChurlish
Thanks for your review. Maybe last line is wrong but it seems to work. About Api 17, this answer was written in 2013, so API didn't exist or was too young.Cranky
Chek on all devices, on Huawei I had an issue that values were shifted.Ophthalmology
Hey mate, I know this is an old question but I was just wondering why are you subtracting the 140 in this line. dbm = Integer.parseInt(parts[8])-140;Hoad
If I remember, it's because the "unit" for 4G-LTE is not the same as 3G and the conversion is to substract 140 (dont know why). You can test it. In 4G, the value return will be positive if you don't add -140, which is impossible for a signal strenght. I search on Google why -140 but didn't find anything relevant...Cranky
For LTE, parts[14] is probably Timing Advance given by getTimingAdvance() from API level 17 and up.Chanel
M
14

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!

Mweru answered 8/1, 2012 at 23:1 Comment(9)
Link : Not found ! Delete this response or update your link please !Cranky
Most of the links were not important. Source code is still available on GitHub. What's most important is that you see there are inconsistencies in how vendors implemented the APIs so it will ultimately require some effort on your part to build a tool that can accurately replicate the device's status bar/ Settings interface.Mweru
ok, link is good. Does your code do something like mine (response below), isn't it ?Cranky
The code is just a utility to use reflection to see the available APIs, it won't give signal strength explicitly, but it's useful for profiling devices that are the exception to the rule. I recommend using it to fix "problem devices" where you get an influx in negative emails/ comments. This is especially important for devices that supported technologies like LTE before any APIs were public for them.Mweru
Hi Tom, I already made that you said, but still I need convert the values of cid (a bigger value) for correct lte cid (a smaller value). Do you know how I make this? Thanks!Plumose
@WilliamLopes I'm actually not sure, I don't claim to understand any of the signal-related values, I just offered a way to get them if they're needed.Mweru
@Plumose In LTE the last byte of the cid is the sector. short_cid = long_cid / 0x100Behrens
This repository has been archived. Is there any other option ?Swamy
@ArifulHaque This was from 2014, I'm sure the APIs have changed since the very early days of Android 14. If nothing else, Google's Android certification requires OEM conform to certain standards so the default SignalStrength API may now suffice in a way it didn't a decade ago in 2014 when fragmentation was pervasive. developer.android.com/reference/android/telephony/…Mweru
K
9

This is complete working implementation of a sample app which uses a reflection 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());
            }
    }
}
Keller answered 29/7, 2015 at 9:42 Comment(1)
can you tell me the max and min length of Strength?Nanji
T
-1

You need to register a PhoneStateListener with LISTEN_SIGNAL_STRENGTHS. You will then get a callback with the current signal strength, and future callbacks with updates.

Tletski answered 5/4, 2011 at 0:40 Comment(3)
The SignalStrength object does not include the ability to get information from a 4G LTE radio, only CDMA, EVDO, and GSM. There is a hidden API for Wimax, but I have found nothing for UMTS LTE.Mweru
What hiddent API did you find for wimax ? Do you have alink for that ?Manoff
The hidden APIs for WiMAX are inconsistent across OEMs so I suggest that you check out the link above to our blog in my answer. None of it is related to SignalStrength, it is all in separate classes and services, you will need a combination of Reflection and Intents to obtain these results in the form of an RSSI, then you'll need to calculate what that actually means.Mweru

© 2022 - 2024 — McMap. All rights reserved.