6

Is there way to clear the dns cache of android device pogrammatically??.I search lot on google but didnt find anything regarding this.

greenfxpips.com
  • 200
  • 1
  • 3
  • 12

1 Answers1

1

As root, do in a shell:

ndc resolver flushdefaultif

And if you want to do it programatically, try this piece of code:

    public boolean reboot() {
    Process proc = null;
    try {
        proc = Runtime.getRuntime().exec("su");
        proc.getOutputStream().write(("ndc resolver flushdefaultif").getBytes());
        return proc.waitFor() == 0;
    } catch (IOException e) {
        e.printStackTrace();
    }
    catch (InterruptedException e) {
        e.printStackTrace();
    }

    return false;
}
Henrique de Sousa
  • 5,727
  • 49
  • 55
  • 1
    On Android 4.3, at least, you can open an `adb shell` console, and give the command `ndc resolver flushdefaultif` which will be shown as "command succeeded" (while `ndc resolver flushdefault` is "500 0 Resolver unknown command") ... and when you ping your dynamic server from an `adb shell` again, it will still fail. – Jon Shemitz Feb 25 '14 at 21:34