0

I have get UnknownhostException in parsing JSON data from server,

My URL working on :

http://jsonlint.com

on real device browser(data plan only)

Sometimes its working on PC browser and sometimes not.

Actually I have get the wifi issue, Sometimes its working on wifi connection, when its not, I have restarted my wifi and its worked, and after some time the same issue came,

I want to get the permanent solution for this wifi connection issue, Restarting the Wifi is never a solution on the application user side,

What is the exact problem and solution also...

Rohit
  • 687
  • 5
  • 22
  • some time wifi network is on but in that network there is no internet connection dude so try to clear both things wifi network is different from internet so i think that time this condition is meet. – Bhanu Sharma Feb 12 '14 at 11:20
  • @BhanuSharma You r right, but when i am testing the URL, the n/w connection is also on, I am sure about that... – Rohit Feb 12 '14 at 11:23
  • ohk i give u to find wifi speed throught network so u just find speed if it will greater then good speed then only controler go in next code other wise show pop up for no internet – Bhanu Sharma Feb 12 '14 at 11:24
  • @BhanuSharma I don't think this is about the n/w speed, because url runs successfully on my 2g data plan, it is so slow, takes almost 2-3 minutes to respond, but every time I got a response from server – Rohit Feb 12 '14 at 11:27
  • from which network u got error WIFI or DATAPLAN – Bhanu Sharma Feb 12 '14 at 11:29
  • link speed from my wifi is -68 and from my 2g aircel data plan is -200 – Rohit Feb 12 '14 at 11:37
  • it show in negative (-ve) sign – Bhanu Sharma Feb 12 '14 at 11:38
  • yes it's a negative value, what it means??? – Rohit Feb 12 '14 at 11:38
  • just mention that your speed will always higher to -20 like -21 ,-22,-23 if it will go higher like -19,-18 and so on that means speed is slow :) – Bhanu Sharma Feb 12 '14 at 11:40
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47315/discussion-between-bhanu-sharma-and-android) – Bhanu Sharma Feb 12 '14 at 11:41
  • No, I haven't completed. – Rohit Feb 12 '14 at 12:33

2 Answers2

0

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.
    
nKn
  • 13,691
  • 9
  • 45
  • 62
0
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
                        int linkSpeed = wifiManager.getConnectionInfo().getRssi();

                            System.out.println("Link Speed is======"+linkSpeed);

It will give u wifi speed so just mention one speed if that speed come then only do next work

Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49