Android 如何获得信号强度?
是最接近我需要的,但我面临的问题是没有构造函数来使用这个类,我试图创建一个新类并扩展它,但没有成功,android文档很好,没有提供一小段代码,我不知道该怎么做 我使用的是不支持该类的API 8,我应该怎么做?Android 如何获得信号强度?,android,signal-strength,Android,Signal Strength,是最接近我需要的,但我面临的问题是没有构造函数来使用这个类,我试图创建一个新类并扩展它,但没有成功,android文档很好,没有提供一小段代码,我不知道该怎么做 我使用的是不支持该类的API 8,我应该怎么做?TelephonyManager TelephonyManager=(TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE); TelephonyManager telephonyManager = (Tel
TelephonyManager TelephonyManager=(TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE);
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> all = telephonyManager.getAllCellInfo();
CellInfoGsm cellinfogsm = (CellInfoGsm) all.get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
int strengthDbm = cellSignalStrengthGsm.getDbm();
List all=telephonyManager.getAllCellInfo();
cellinfogscellinfogsm=(CellInfoGsm)all.get(0);
CellSignalStrengthGsm CellSignalStrengthGsm=cellinfogsm.getCellSignalStrength();
int-strengthDbm=cellSignalStrengthGsm.getDbm();
对于API 17+,应该可以正常工作。我不知道有什么API可以帮助我用API17做了一个新项目来测试这一点。它会给出错误消息“无法解析符号上下文”,即第一行中的消息。最有可能是
上下文
引用了您的活动
。()我尝试了这个方法,但没有成功:TelephonyManager TelephonyManager=(TelephonyManager)activity_main.getSystemService(Context.TELEPHONY_SERVICE);如果您使用的是Activity
trygetApplicationContext().getSystemService..
则“列表”列表始终返回空,我在这里了解到,它并不是在所有设备上都实现的: