Home:ALL Converter>Change DNS programmatically in Android

Change DNS programmatically in Android

Ask Time:2012-12-22T22:12:55         Author:dthomasen

Json Formatter

I'm writing an app to change the DNS of my Android device. I've successfully gotten the current DNS info out, I can't however figure out how to set it to the new values.

I've tried the following approach:

android.provider.Settings.System.putString(v.getContext().getContentResolver(),android.provider.Settings.System.WIFI_USE_STATIC_IP, "192.168.100.102");
android.provider.Settings.System.putString(v.getContext().getContentResolver(),android.provider.Settings.System.WIFI_STATIC_DNS1, "192.168.0.2");
android.provider.Settings.System.putString(v.getContext().getContentResolver(),android.provider.Settings.System.WIFI_STATIC_DNS2, "192.168.0.3");
android.provider.Settings.System.putString(v.getContext().getContentResolver(),android.provider.Settings.System.WIFI_STATIC_GATEWAY, "192.168.0.1");
android.provider.Settings.System.putString(v.getContext().getContentResolver(),android.provider.Settings.System.WIFI_STATIC_NETMASK, "255.255.255.0");
android.provider.Settings.System.putString(v.getContext().getContentResolver(),android.provider.Settings.System.WIFI_STATIC_IP, "1");

Didn't seem to change anything though.

(I'm sure the values I'm inputting aren't correct - as of now I just want to see some changes in my settings)

Author:dthomasen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14003544/change-dns-programmatically-in-android
yy