安卓VPN服务生成器.establish()返回空值。

5
我正在尝试在安卓上使用VPN服务。为了达到这个目的,我认为必须使用安卓SDK提供的VpnService类中提供的Builder类。现在,当我尝试这样做时,方法...
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 = null”。你确定它不会在theInterface.close();处崩溃吗? - Andy Turner
谢谢您的回复,我相信这不会影响结果,我刚刚尝试删除了那段代码并重新运行了一遍,结果还是一样的。 - Targa
我遇到了同样的问题,但是当我重新启动我的设备(LG G3)时,VPN就无法连接了,我还在寻找解决办法。 - Roger Rabbit
谢谢您的评论,我真的希望有人能解决这个问题,因为我还没能解决它... - Targa
1个回答

7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接