如何在Android中为3G移动网络更改Dns?

如何在Android中为3G移动网络更改Dns?,android,dns,android-networking,Android,Dns,Android Networking,例如,我们可以使用此代码更改Dns或其他网络信息 public static void setDNS(InetAddress dns, WifiConfiguration wifiConf) throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException { Object linkProperties = getField(w

例如,我们可以使用此代码更改Dns或其他网络信息

public static void setDNS(InetAddress dns, WifiConfiguration wifiConf)
        throws SecurityException, IllegalArgumentException,
        NoSuchFieldException, IllegalAccessException {

    Object linkProperties = getField(wifiConf, "linkProperties");
    if (linkProperties == null)
        return;

    ArrayList<InetAddress> mDnses = (ArrayList<InetAddress>)getDeclaredField(
            linkProperties, "mDnses");
    mDnses.clear(); // or add a new dns address , here I just want to
                    // replace DNS1
    mDnses.add(dns);
}
publicstaticvoidsetdns(InetAddress-dns,WifiConfiguration-wifiConf)
抛出SecurityException、IllegalArgumentException、,
NoSuchFieldException,IllegalAccessException{
对象linkProperties=getField(wifiConf,“linkProperties”);
if(linkProperties==null)
回来
ArrayList mDnses=(ArrayList)getDeclaredField(
链接属性(“MDNSE”);
mDnses.clear();//或者添加一个新的dns地址,在这里我只想
//替换DNS1
添加(dns);
}
我想更改3G移动网络的Dns?请帮助我。。。 我已经尝试过这个,如果有人知道这个plz的任何课程,请告诉我,我会找到更多

Context context = DnsCacheService.this.getBaseContext();
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Object prop = cm.getClass().getMethod("getActiveLinkProperties").invoke(cm);
Collection<InetAddress>    currDnses = ((LinkProperties) prop).getDnsServers();
Collection<InetAddress> newDnses = new ArrayList();
InetAddress dnstoAdd = InetAddress.getByName("127.0.0.1");
newDnses.add(dnstoAdd);
newDnses.add(dnstoAdd);
//prop.setDnsServers(newDnses);
Context Context=DnsCacheService.this.getBaseContext();
ConnectivityManager cm=(ConnectivityManager)context.getSystemService(context.CONNECTIVITY_服务);
Object prop=cm.getClass().getMethod(“getActiveLinkProperties”).invoke(cm);
集合currDnses=((LinkProperties)prop).getDnsServers();
集合newDnses=newarraylist();
InetAddress dnstoAdd=InetAddress.getByName(“127.0.0.1”);
newDnses.add(dnstoAdd);
newDnses.add(dnstoAdd);
//道具设置服务器(新服务器);

谢谢@ArifulHaque,但你对此有什么想法吗?欢迎来到SO!我刚刚更正了问题的格式。如果我对问题域有经验,我肯定会回答你:)。