我正在尝试连接AP的Wi-Fi信号强度。当我尝试运行以下代码时,不会返回任何内容/显示错误。
public class Wifi extends uiscenario {
public void onReceive(WifiManager wifiManager) throws UiObjectNotFoundException, InterruptedException, RemoteException, IOException {
System.out.println("level");
int numberOfLevels=4;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
}
如何获得wifi连接的信号强度,以及如何获得wifi的扫描结果并连接到信号强度最强的wifi?
更新了代码
public class Wifi extends UiScenario {
private static WifiManager wifiManager;
public void wifiscan() throws UiObjectNotFoundException,InterruptedException,RemoteException, IOException {
int numberOfLevels=5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
}
在此行中获取错误(WifiInfo wifiInfo = wifiManager.getConnectionInfo();)
答案 0 :(得分:0)
希望它应该有效。它对我来说很好。
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
答案 1 :(得分:0)
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
System.out.println("Link Speed is======"+linkSpeed);
答案 2 :(得分:0)
检查您的清单使用wifi的权限并阅读手机状态您的代码是完美的, 它应该工作其他尝试这个。
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();