Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获得信号强度?_Android_Signal Strength - Fatal编程技术网

Android 如何获得信号强度?

Android 如何获得信号强度?,android,signal-strength,Android,Signal Strength,是最接近我需要的,但我面临的问题是没有构造函数来使用这个类,我试图创建一个新类并扩展它,但没有成功,android文档很好,没有提供一小段代码,我不知道该怎么做 我使用的是不支持该类的API 8,我应该怎么做?TelephonyManager TelephonyManager=(TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE); TelephonyManager telephonyManager = (Tel

是最接近我需要的,但我面临的问题是没有构造函数来使用这个类,我试图创建一个新类并扩展它,但没有成功,android文档很好,没有提供一小段代码,我不知道该怎么做

我使用的是不支持该类的API 8,我应该怎么做?

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
try
getApplicationContext().getSystemService..
则“列表”列表始终返回空,我在这里了解到,它并不是在所有设备上都实现的: