我希望我的应用程序中的网络请求来自特定的DNS,但是我是java的新手,所以我尝试过这样做:
import android.net.VpnService;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.system.OsConstants;
public class DNSChanger extends VpnService {
public void StartTunnel()
{
Builder builder = new Builder();
builder.addAddress("192.168.0.10", 24);
builder.addDnsServer("8.8.8.8"); // replaces with my DNS
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setBlocking(true);
}
builder.setSession("DNS Test");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.allowFamily(OsConstants.AF_INET);
builder.allowFamily(OsConstants.AF_INET6);
}
ParcelFileDescriptor fd = builder.establish();
}
}
但是没有用。请告诉我这段代码有什么问题,或者只是给我一个很好的参考资源