Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

vpn

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.

like image 364
Bas van Dijk Avatar asked Apr 21 '12 21:04

Bas van Dijk


1 Answers

Here the example of using VpnService https://android.googlesource.com/platform/development/+/master/samples/ToyVpn/src/com/example/android/toyvpn

like image 112
saini Avatar answered Sep 21 '22 09:09

saini