我在解析来自服务器的 JSON 数据时遇到了 UnknownhostException,
我的网址正在处理:
在真实设备浏览器上(仅限数据计划)
有时它可以在 PC 浏览器上运行,有时不能。
实际上我遇到了wifi问题,有时它在wifi连接上工作,当它没有时,我重新启动了我的wifi并且它工作了,一段时间后同样的问题来了,
我想得到这个 wifi 连接问题的永久解决方案,重新启动 Wifi 永远不是应用程序用户端的解决方案,
确切的问题和解决方案是什么...
我在解析来自服务器的 JSON 数据时遇到了 UnknownhostException,
我的网址正在处理:
在真实设备浏览器上(仅限数据计划)
有时它可以在 PC 浏览器上运行,有时不能。
实际上我遇到了wifi问题,有时它在wifi连接上工作,当它没有时,我重新启动了我的wifi并且它工作了,一段时间后同样的问题来了,
我想得到这个 wifi 连接问题的永久解决方案,重新启动 Wifi 永远不是应用程序用户端的解决方案,
确切的问题和解决方案是什么...
Usually the UnknownHostException
fires when you cannot resolve the DNS record of the URL you've provided. There's a reasonable timeout for that operation, but if you have a weak WiFi connection or you don't have enough signal on your device, the communication can be interrupted in the middle between sending and receiving the response, so your device doesn't receive the response, thus it thinks it's a DNS timeout.
There are 2 things you can try:
Increase the timeout of the response. This will not help, though, if your communication gets interrupted you already sent the query.
Use the IP address instead:
shut-up@i-kill-you:~$ ping jsonlint.com
PING jsonlint.com (54.243.171.164) 56(84) bytes of data.
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
System.out.println("Link Speed is======"+linkSpeed);
它会给你 wifi 速度,所以只要提到一个速度,如果那个速度来了,那么只做下一个工作