Android手机信号

<3G与2G信号区分>

<BatteryStatsImpl.java>

if (!signalStrength.isGsm()) {

   int dBm = signalStrength.getCdmaDbm();
   if (dBm >= -75) bin = SIGNAL_STRENGTH_GREAT;
   else if (dBm >= -85) bin = SIGNAL_STRENGTH_GOOD;
   else if (dBm >= -95) bin = SIGNAL_STRENGTH_MODERATE;
   else if (dBm >= -100) bin = SIGNAL_STRENGTH_POOR;
   else bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
} else {
   int asu = signalStrength.getGsmSignalStrength();
   if (asu < 0 || asu >= 99) bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
   else if (asu >= 16) bin = SIGNAL_STRENGTH_GREAT;
   else if (asu >= 8) bin = SIGNAL_STRENGTH_GOOD;
   else if (asu >= 4) bin = SIGNAL_STRENGTH_MODERATE;
   else bin = SIGNAL_STRENGTH_POOR;

}

<Phone.java>

GSM信号单位<dBm-asu>换算公式:dBm = -113 -2*asu;

/**
* Get current signal strength. No change notification available on this
* interface. Use <code>PhoneStateNotifier</code> or an equivalent.
* An ASU is 0-31 or -1 if unknown (for GSM, dBm = -113 - 2 * asu).
* The following special values are defined:</p>
* <ul><li>0 means "-113 dBm or less".</li>
* <li>31 means "-51 dBm or greater".</li></ul>
*
* @return Current signal strength as SignalStrength
*/
SignalStrength getSignalStrength();


其它信息:

4G:

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



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
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){
   dbm = Integer.parseInt(parts[8])*2-113;
}
else{
   if (signalStrength.getGsmSignalStrength() != 99) {
                   int intdbm = -113 + 2
                           * signalStrength.getGsmSignalStrength();
                   dbm = Integer.toString(intdbm);
               }
}


//GSM信号单位<dBm-asu>换算公式:dBm = -113 +2*asu;


参考:

http://code.taobao.org/p/cnandroiddocs/src/trunk/telephony/java/android/telephony/CellSignalStrengthLte.java

posted @ 2016-05-31 15:50  vegatate  阅读(435)  评论(0编辑  收藏  举报