Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> 智能手機中顯示信號強度格數

智能手機中顯示信號強度格數

編輯:關於Android編程

在Android4.0的系統中,手機中顯示信號強度格數的代碼在

frameworks\base\telephony\java\android\telephony\SignalStrength.java

getLevel( )函數,該函數是主要用來獲取信號的強度。


[java]
public int getLevel() { 
        int level; 
 
        if (isGsm) { 
            level = getLteLevel(); 
            if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { 
                level = getGsmLevel(); 
            } 
        } else { 
            int cdmaLevel = getCdmaLevel(); 
            int evdoLevel = getEvdoLevel(); 
            if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { 
                /* We don't know evdo, use cdma */ 
                level = cdmaLevel; 
            } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { 
                /* We don't know cdma, use evdo */ 
                level = evdoLevel; 
            } else { 
                /* We know both, use the lowest level */ 
                //level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;  
                level = cdmaLevel > evdoLevel ? cdmaLevel : evdoLevel; 
            } 
        } 
        if (DBG) log("getLevel=" + level); 
        return level; 
    } 

public int getLevel() {
        int level;

        if (isGsm) {
            level = getLteLevel();
            if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
                level = getGsmLevel();
            }
        } else {
            int cdmaLevel = getCdmaLevel();
            int evdoLevel = getEvdoLevel();
            if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
                /* We don't know evdo, use cdma */
                level = cdmaLevel;
            } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
                /* We don't know cdma, use evdo */
                level = evdoLevel;
            } else {
                /* We know both, use the lowest level */
                //level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
                level = cdmaLevel > evdoLevel ? cdmaLevel : evdoLevel;
            }
        }
        if (DBG) log("getLevel=" + level);
        return level;
    }getCdmaLevel( )獲取CdmaLevel,同樣也有getEvdoLevel( )函數,在上一個函數中,通過比較Evdo和Cdma的強度,來最終確定信號的顯示強度,也就是我們在通知欄裡看到的信號格數。
[java]
public int getCdmaLevel() { 
        final int cdmaDbm = getCdmaDbm(); 
        final int cdmaEcio = getCdmaEcio(); 
        int levelDbm; 
        int levelEcio; 
 
        if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT; 
        else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD; 
        else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE; 
        else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR; 
        else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 
 
        // Ec/Io are in dB*10  
        if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT; 
        else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD; 
        else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE; 
        else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR; 
        else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 
 
        int level = (levelDbm < levelEcio) ? levelDbm : levelEcio; 
        if (DBG) log("getCdmaLevel=" + level + ",cdmaDbm=" + cdmaDbm + ",cdmaEcio=" +cdmaEcio); 
        return level; 
    } 

public int getCdmaLevel() {
        final int cdmaDbm = getCdmaDbm();
        final int cdmaEcio = getCdmaEcio();
        int levelDbm;
        int levelEcio;

        if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT;
        else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD;
        else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE;
        else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR;
        else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

        // Ec/Io are in dB*10
        if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
        else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
        else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
        else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR;
        else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

        int level = (levelDbm < levelEcio) ? levelDbm : levelEcio;
        if (DBG) log("getCdmaLevel=" + level + ",cdmaDbm=" + cdmaDbm + ",cdmaEcio=" +cdmaEcio);
        return level;
    }

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved