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?