How do I get LTE information from Android code?

Source: Internet
Author: User

Recently, in order to successfully obtain the signal strength of LTE, a number of methods have been tried:

(1) Parse the signalstrength string, but different phone devices get a different sequence of strings, the code is as follows:

private Phonestatelistener Phonestatelistener = new Phonestatelistener ()
   {
Public void Onsignalstrengthschanged (signalstrength ss)
           {
super.onsignalstrengthschanged (ss);
signalinformation = ss.tostring ();
signalstrength = Ss.getgsmsignalstrength ();
String [] LTE = Signalinformation.split ("");
mltesignalstrength = lte[11];
            }

}

(2) api>17, using Cellinforlte, the return value I get is always empty, the code is as follows:

public int GETMOBILEDBM (context context)
{
int dbm =-1;
Telephonymanager TM = (Telephonymanager) context.getsystemservice (context.telephony_service);
list<cellinfo> cellinfolist;
if (Build.VERSION.SDK_INT >= build.version_codes. JELLY_BEAN_MR1)
{
cellinfolist = Tm.getallcellinfo ();
if (null! = cellinfolist)
{
For (Cellinfo cellinfo:cellinfolist)
{
if (cellinfo instanceof cellinfogsm)
{
cellsignalstrengthgsm cellsignalstrengthgsm = ((cellinfogsm) cellinfo). Getcellsignalstrength ();
dbm = cellsignalstrengthgsm.getdbm ();
}
else if (cellinfo instanceof CELLINFOCDMA)
{
CELLSIGNALSTRENGTHCDMA CELLSIGNALSTRENGTHCDMA =
((CELLINFOCDMA) cellinfo). Getcellsignalstrength ();
dbm = cellsignalstrengthcdma.getdbm ();
}
else if (cellinfo instanceof CELLINFOWCDMA)
{
if (Build.VERSION.SDK_INT >= build.version_codes. JELLY_BEAN_MR2)
{
CELLSIGNALSTRENGTHWCDMA CELLSIGNALSTRENGTHWCDMA =
((CELLINFOWCDMA) cellinfo). Getcellsignalstrength ();
dbm = cellsignalstrengthwcdma.getdbm ();
}
}
else if (cellinfo instanceof Cellinfolte)
{
Cellsignalstrengthlte Cellsignalstrengthlte = ((Cellinfolte) cellinfo). Getcellsignalstrength ();
dbm = cellsignalstrengthlte.getdbm ();
}
}
}
}
return dbm;
}

(3) The third method applies to most devices, directly on the code:

Private class Signalstrengthlistener extends Phonestatelistener
{
Public void onsignalstrengthschanged (signalstrength signalstrength)
{
super.onsignalstrengthschanged (signalstrength);

try {
Lte_sinr = (Integer) signalstrength.getclass (). GetMethod ("Getltesignalstrength"). Invoke (Signalstrength);
LTE_RSRP = (Integer) signalstrength.getclass (). GetMethod ("GETLTERSRP"). Invoke (Signalstrength);
LTE_RSRQ = (Integer) signalstrength.getclass (). GetMethod ("Getltersrq"). Invoke (Signalstrength);
Lte_rssnr = (Integer) signalstrength.getclass (). GetMethod ("Getlterssnr"). Invoke (Signalstrength);
Lte_cqi = (Integer) signalstrength.getclass (). GetMethod ("Getltecqi"). Invoke (Signalstrength);
} catch (Exception e) {
e.printstacktrace ();
return;
}
}

How do I get LTE information from Android code?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.