简体   繁体   English

在Android中以编程方式更改DNS

[英]Change DNS programmatically in Android

I'm writing an app to change the DNS of my Android device. 我正在编写一个应用程序来更改我的Android设备的DNS。 I've successfully gotten the current DNS info out, I can't however figure out how to set it to the new values. 我已成功获取当前的DNS信息,但我无法弄清楚如何将其设置为新值。

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 ) 我确定我输入的值不正确 - 截至目前我只想看到我的设置有些变化

Did you add the permission? 你添加了许可吗? [Link] [链接]

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM