Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically setting up a vpn on Android

I have found the following code to establish a new vpn programmatically but I do not know how to use it to create my app

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

can anyone please help me with a sample code? Is it even possible to to achieve dis?

like image 250
user3073428 Avatar asked Dec 06 '13 07:12

user3073428


People also ask

Can I create my own VPN on Android?

VPN support is baked into Android, so you can easily set it up via the phone's Settings menu without downloading an app. Open the Settings menu of the phone. Keep in mind that the instructions below may vary depending on what device you have. Tap on Wi-Fi & Internet or Wireless & networks.


1 Answers

Note: this answer is dated and may now be inaccurate.

Take a look at this question: How to configure VPN programmatically?

While yours isn't necessarily a duplicate, the answer is likely the same, in that you're going to need to expose the hidden API (if it's available) or worse, be dependent on the device being rooted.

Understandably, programmatically creating a VPN connection poses an inherent security risk for the end user, and shouldn't be implemented without consideration.

like image 143
brandonscript Avatar answered Oct 14 '22 15:10

brandonscript