我在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);
Run Code Online (Sandbox Code Playgroud)
这配置了一个新的VPN.我只想连接现有的VPN.
这个页面http://developer.android.com/reference/android/net/VpnService.html描述了如何实现自己的VPN服务,这也不是我想要的.
| 归档时间: |
|
| 查看次数: |
5466 次 |
| 最近记录: |