Android – Howto connect to a VPN, which is already setup in an Android phone, programmatically

androidvpn

I have configured a VPN connection in my Android phone. Now I would like to connect this VPN via a widget. How can I initiate a connection programmatically? Most code assumes there is no VPN setup yet, but this is not where I am looking for. I look especially for code which connects to an already configured VPN.

On http://code.google.com/p/android/issues/detail?id=8915 I have found this code:

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);

Which configures a new VPN. I want just to connect an existing VPN.

This page http://developer.android.com/reference/android/net/VpnService.html describes how to implement your own VPN service, which is also not what I am looking for.

Related Question