Android – Create VPN in android 4.0 using VpnService

androidvpn

I want to create a vpn connection like PPTP, IPSec, etc in android 4.0 platform.

Android 4.0 providers us a new class called VpnService, I've already check out the demo project ToyVpn, but I still got some problem.

ToyVpn seems create a custom vpn implementation, we need to handle the details of the vpn connection.

I just want to create vpn like system setting activity, so any one got some idea? please let me know…

ps. In android 2.3 and early, we can use reflection to call system hidden class to create the vpn like system setting page. But from android 4.0 it doesn't work any more.

Thanks!
Ruochao

Best Answer

I know it's been some time, but I've been fussing with this for a while now and thought I'd chime in for those who come across this.

Android has offered the VpnService class in the API for Android 4.0+. This class allows a user-land application (i.e. your app) to redirect DNS requests and requests matching defined Routes to a new TUN-like interface which is managed by your app. This does not out-of-the-box implement encryption or anything we'd expect from a usual VPN.

There are variants available by others:

Each of these projects use JNI to bridge the Android VpnService to an existing VPN solution ported to Android.