Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method to pass username and password in VpnService.Builder

Tags:

android

vpn

I am developing the application in which I want to use VPN network. to create VPN network in device we need to configure it from (settings-wireless and network-VPN settings) menu of device.

I want to do this many settings via code with hard-coded information.

From API level 4.0 android provides API to handle the VPN services.

To know the implementation of this methods I used the Sample project of Android ToyVPN. But in this many methods I didn't find any method to pass username and password. information which I have to connect VPN network is.

  1. VPN Server name
  2. Username
  3. Password

Using this three information I am successfully connecting to VPN network if I am configuring manually from device. But I want to do this programmatically. Here is the class file which is used to connect to VPN network. ToyVpnClient.java and ToyVpnService.java. in addition to this sample application is crashes in device.

Any help will be appreciated.

like image 223
Juned Avatar asked Jul 13 '12 13:07

Juned


1 Answers

The VpnService you are talking about is not what you think. It's just a framework for you to create your own VPN solution. Once established, you'll get all communication on the network (IP) layer and you can do anything you want with it, e.g., encrypt it and send it to your server - the example for this is the ToyVpn project found in /samples/android-14/ directory. You also need a your own server side code to do the decryption and the necessary routing of the traffic.

Unfortunately you can't set the built-in android VPN programmatically. The best you can do is to show a dialog to the user explaining how to set it and then pop up the system settings with the correct screen showing.

like image 142
cermak.cz Avatar answered Sep 19 '22 04:09

cermak.cz