【问题标题】:Howto connect to a VPN, which is already setup in an Android phone, programmatically如何以编程方式连接到已在 Android 手机中设置的 VPN
【发布时间】:2012-05-03 00:41:33
【问题描述】:

我已在我的 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服务,这也不是我想要的。

【问题讨论】:

  • 请发布一些代码并更好地解释您尝试过的内容。
  • 我还没有任何代码,这正是问题所在。我正在寻找有关如何连接和现有 VPN 的示例代码。
  • 您发布的示例只是您发布的链接中的“我想要的”示例。
  • 如果您愿意,我可以向您展示如何在 2.2 和 2.3 中非常轻松地做到这一点。我有一个工作示例,我自己现在正在寻找一种方法在 4.x 上做同样的事情。
  • slott,请在 2.2 和 2.3 中解释如何执行此操作。我的电子邮件:anivaler@tut.by。谢谢。

标签: android vpn


【解决方案1】:
猜你喜欢
  • 2012-06-05
  • 2011-10-24
  • 2011-10-27
  • 2013-12-23
  • 2015-10-21
  • 2015-01-04
  • 2014-09-18
  • 2014-04-26
  • 2013-09-24
相关资源
最近更新 更多