Android UnknownHostException Facebook SDK

后端 未结 3 1464
生来不讨喜
生来不讨喜 2021-01-05 21:55

Here is the situation. My app runs fine, and is able to establish connections with URLs. BUT after a few hours of leaving the app running, all of a sudden the Facebook reque

3条回答
  •  臣服心动
    2021-01-05 22:49

    I don't have any core conceptual knowledge about network connectivity and DNS caching and TTL management.

    but the same problem occurred to me and at that time Just As a Workaround I have made few changes in the Facebook project's Util.java [The source project of the Facebook SDK] and then used it for my project. That two changes is just used from different stackoverflow answers.

    In the function openUrl(String url, String method, Bundle params)

    Replace this line,

     HttpURLConnection conn =
                (HttpURLConnection) new URL(url).openConnection();
    

    with these lines,

            try {
                InetAddress i = InetAddress.getByName(url);
            } catch (UnknownHostException e1) {
                e1.printStackTrace();
            }
    
            HttpURLConnection conn = (HttpURLConnection) new URL(url)
                    .openConnection();
            conn.setConnectTimeout(50000);
    

    And my problem was reduced.

提交回复
热议问题