频道栏目
首页 > 程序开发 > 移动开发 > Android > 正文
智能手机中显示信号强度格数
2013-06-09 09:21:34      个评论      
收藏   我要投稿

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;
    }

 

点击复制链接 与好友分享!回本站首页
上一篇:Android倚天剑之Notification之动感地带
下一篇:Android之消息推送聊天实现
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站