gpt4 book ai didi

android - 如何以编程方式连接到已在 Android 手机中设置的 VPN

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:57 24 4
gpt4 key购买 nike

我已经在我的 Android 手机中配置了 VPN 连接。现在我想通过一个小部件连接这个 VPN。如何以编程方式启动连接?大多数代码假定还没有 VPN 设置,但这不是我要找的地方。我特别寻找连接到已配置 VPN 的代码。

关于 http://code.google.com/p/android/issues/detail?id=8915我找到了这段代码:

VpnService service = context.getSystemService(VPN_SERVICE);
VpnProfile profile = VpnProfile.create(L2TP_PROFILE);
profile.setName(myServerName);
profile.setServerName(myServerAddress);
profile.setRouteList(“192.168.1.0/255.255.255.0,192.168.10.0/255.255.255.0”);

service.connect(profile, myUserName, myPassword);
service.setNotificationIntent(myIntent);

配置一个新的 VPN。我只想连接现有的 VPN。

本页http://developer.android.com/reference/android/net/VpnService.html描述了如何实现您自己的 VPN 服务,这也不是我想要的。

最佳答案

关于android - 如何以编程方式连接到已在 Android 手机中设置的 VPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10262997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com