androiddnsloopjandroid-async-http

Overriding DNS for an application on Android


I have a simple question regarding DNS on Android.

Is there any way to change DNS server just for my own app?

More specifically I'm using loopj's Android AsyncHttp lib (http://loopj.com/android-async-http/).

Looking at the source, I've noticed this comment at setProxy method:

/**
     * Sets the Proxy by it's hostname and port
     *
     * @param hostname the hostname (IP or DNS name)
     * @param port     the port number. -1 indicates the scheme default port.
     */
    public void setProxy(String hostname, int port) {
        final HttpHost proxy = new HttpHost(hostname, port);
        final HttpParams httpParams = this.httpClient.getParams();
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

So I assumed that putting for example "8.8.8.8" and -1 as arguments of setProxy I could reach my goal, but obviously I was wrong.

Suggestions?


Solution

  • I think you have misunderstood the setProxy() method, it is used to set the proxy for your HttpClient.

    hostname: could be an IP address i.e: "192.168.1.100" or a DNS name like "proxy.example.com". port: it is the tcp/udp port on which your proxy server is listening.

    As for your request of changing the DNS i think it is not possible.