我正在尝试在安卓上使用VPN服务。为了达到这个目的,我认为必须使用安卓SDK提供的VpnService类中提供的Builder类。现在,当我尝试这样做时,方法...
返回 null。这是我编写的完整方法;
代码崩溃于:
调试时,调试器在程序的整个执行过程中都会显示“theInterface = null”。
编辑:
我已经查看了位于android.net.VpnService中的Builder类。
在这个类中,似乎有一个隐藏的类(IConnectivityManager),也许我的问题与此有关...
这是我所说的代码片段。
builder.establish()
返回 null。这是我编写的完整方法;
// If theInterface still exists from last time, reuse it, it has the same parameters.
if (theInterface != null) {
return;
}
// configure the VPN settings.
Builder builder = new Builder();
builder.setMtu(1500);
builder.addAddress("10.0.2.0", 32);
builder.addRoute("0.0.0.0", 0);
try {
theInterface.close();
} catch (Exception e) {
// Ignore
}
theInterface = builder.establish();
Log.i(TAG + "IMPORTANT", builder.toString());
代码崩溃于:
Log.i(TAG + "IMPORTANT", builder.toString());
调试时,调试器在程序的整个执行过程中都会显示“theInterface = null”。
编辑:
我已经查看了位于android.net.VpnService中的Builder类。
在这个类中,似乎有一个隐藏的类(IConnectivityManager),也许我的问题与此有关...
这是我所说的代码片段。
/**
* Use IConnectivityManager since those methods are hidden and not
* available in ConnectivityManager.
*/
private static IConnectivityManager getService() {
return IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
}
theInterface.close();
处崩溃吗? - Andy Turner