Android: Sample Code to Connect to Vpn in Android 4.0 Using Vpnservice API

Set a VPN connection programmatically on android 4.0

Basically the VPN API introduced in Android 4.0+ only allows you to implement your own VPN implementation. It does no more than opening the Linux TUN device and pass the file descriptor to you, plus setting up the routes/DNS servers/etc you provided. The whole VPN protocol implementation is solely up to you.

So the short answer is: no. you can't use the VPN API to set up any of the

PPTP, L2TP, L2TP/IPSec PSK or L2TP/IPSec CRT

VPN connections, unless you roll out your own implementation of the mentioned VPN types.

That being said, you may still try to broadcast an Intent to bring your user to the system VPN settings activity and ask them to manually configure/start the VPN.

Oh and one more thing to add. At the time of this writing, Android's latest DevicePolicyManager (API level 21) already provides WiFi settings provisioning support. I would personally guess that Google might continue to add more Android for Work features, which may include VPN provisioning support you need. I/O 2015 is only a few days away so let's wait and see...

VpnService Android 4.0

The VPNService API is not for configuring the system VPN Services but for implementing your own VPN solution. You can for example implement protocols that are not implemented by the system like OpenVPN.

To use pptp with the VPNService API you need to implement the PPTP protocol yourself (or port an existing implementation (should not be difficult))



Related Topics



Leave a reply



Submit