6

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3073428
  • 63
  • 1
  • 1
  • 5

1 Answers1

2

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.

Community
  • 1
  • 1
brandonscript
  • 68,675
  • 32
  • 163
  • 220
  • sorry for replying so late but i had been trying to find all possible ways.I used this link https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/ to access hidden apis but i couldnt get access to internal apis So i searched for other options and tried working on the openvpn project which uses the vpn service provided by android . But now am stuck at configuring ndk .I have downloaded the ndk but how do i setup its path in eclipse ? I literally know nothing about ndk . Can you help me – user3073428 Dec 16 '13 at 18:20
  • Eek, I don't know anything about ndk either... Might be best to write up a new question for where you're at currently to see if anyone can help? – brandonscript Dec 16 '13 at 18:22
  • hmm ok anyway thanx for your help – user3073428 Dec 17 '13 at 04:46