得到SignalStrength没有使用PhoneStateListener onSignalStrengthchanged [英] get SignalStrength without Using PhoneStateListener onSignalStrengthchanged

查看:651
本文介绍了得到SignalStrength没有使用PhoneStateListener onSignalStrengthchanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有人知道如何获得的信号强度,而不必调用onSignalStrengthChanged。与onSignalStrengthchanged的问题是,它是被称为当信号强度的变化和我需要根据不同的标准来获得signalstrength的值。

does anyone know how to get the signal strength without having to call the onSignalStrengthChanged. The problem with onSignalStrengthchanged is that is it called when the signal strength changes and I need to get the value of signalstrength according to a different criteria.

在此先感谢。

推荐答案

在API级别17的,这里的一些code,可以在活动中使用(或任何其他上下文子类):

On API level 17 only, here's some code that can be used in an Activity (or any other Context child class):

import android.telephony.CellInfo;
import android.telephony.CellInfoCdma;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellSignalStrengthCdma;
import android.telephony.CellSignalStrengthGsm;
import android.telephony.CellSignalStrengthLte;
import android.telephony.TelephonyManager;

try {
    final TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    for (final CellInfo info : tm.getAllCellInfo()) {
        if (info instanceof CellInfoGsm) {
            final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
            // do what you need
        } else if (info instanceof CellInfoCdma) {
            final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
            // do what you need
        } else if (info instanceof CellInfoLte) {
            final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
            // do what you need
        } else {
            throw new Exception("Unknown type of cell signal!");
        }
    }
} catch (Exception e) {
    Log.e(TAG, "Unable to obtain cell signal information", e);
}

Android系统

previous版本需要咨询的听众,没有其他替代方案(见此链接)。

Previous versions of Android require you to call the listener, there is no other alternative (see this link).

另外,还要确保你的应用程序中包含相应的权限。

Also ensure that your application contains the appropriate permissions.

这篇关于得到SignalStrength没有使用PhoneStateListener onSignalStrengthchanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆