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


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 I have found this code:

VpnService service = context.getSystemService(VPN_SERVICE);
VpnProfile profile = VpnProfile.create(L2TP_PROFILE);

service.connect(profile, myUserName, myPassword);

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

This page describes how to implement your own VPN service, which is also not what I am looking for.

Related Question