7

I'd like to flush DNS in my Android app due to some external event. I've noticed that Android system code uses something like this:

final Intent intent = new Intent(Intent.ACTION_CLEAR_DNS_CACHE);

to clear DNS cache but it doesn't appear to be available in the user code. Are there any alternatives? Thanks.

alexbtr
  • 3,292
  • 2
  • 13
  • 25

2 Answers2

1

This may work only if your Android is rooted

Using the adb tool you can clear cache like that (tested on the current Android x86 image)

os.system(f'adb -s {host} shell am force-stop com.android.chrome')
os.system(f'adb -s {host} shell ndc resolver clearnetdns wlan0')
os.system(f'adb -s {host} shell ndc resolver clearnetdns wifi_eth')

So, if your android is rooted, you could try to execute the same commands (without adb -s ... shell) prefix.

Antigluk
  • 1,176
  • 2
  • 11
  • 30
0

Manually you can Open Chrome and type

chrome://net-internals/#dns

This will take you to the DNS lookup page where you will find a "Clear host cache" putton, push it.

cpu
  • 1
  • 2