Ahm*_*mad 23 vpn android android-4.0-ice-cream-sandwich
我正在以编程方式在Android设备上设置VPN连接.我成功地使用OS 2.3.5和之前的设备(我使用反射来访问隐藏的类).但是在android 4.0中,他们摆脱了旧类并使用了VPNService类.
我认为最好的起点是使用Android提供的ToyVPN示例,但我面临很多挑战.在示例代码中,他们只需要发送服务器地址:
InetSocketAddress server = new InetSocketAddress(mServerAddress, Integer.parseInt(mServerPort));
Run Code Online (Sandbox Code Playgroud)
然后通过打开频道创建VPN隧道:
tunnel = DatagramChannel.open();
Run Code Online (Sandbox Code Playgroud)
但在我的情况下,我需要发送服务器地址,用户名和密码.到目前为止,我还没有想出如何这样做.我最好的猜测是做这样的事情:
Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user","pass".toCharArray());
}});
try {
// Create a DatagramChannel as the VPN tunnel.
tunnel = DatagramChannel.open();
Run Code Online (Sandbox Code Playgroud)
但这没效果.所以我要问的是:
编辑
我忘了提到我需要指定VPN类型(PPTP,L2TP,L2TP/IPSec PSK或L2TP/IPSec CRT).
基本上,Android 4.0+中引入的VPN API只允许您实现自己的 VPN实现.它只不过是打开Linux TUN设备并将文件描述符传递给您,以及设置您提供的路由/ DNS服务器/等.整个VPN协议实现完全取决于您.
所以简短的回答是:不.你不能使用VPN API来设置任何一个
PPTP,L2TP,L2TP/IPSec PSK或L2TP/IPSec CRT
VPN连接,除非您推出自己提到的VPN类型的实现.
话虽这么说,你仍然可以尝试广播一个Intent,让你的用户进入系统VPN设置活动,并要求他们手动配置/启动VPN.
哦,还有一件事要补充.在撰写本文时,Android的最新DevicePolicyManager(API级别21)已经提供了WiFi设置配置支持.我个人猜测Google可能会继续添加更多Android for Work功能,其中可能包括您需要的VPN配置支持.I/O 2015距离我们只有几天了,所以让我们拭目以待......
| 归档时间: |
|
| 查看次数: |
9287 次 |
| 最近记录: |