Method to pass username and password in VpnService.Builder

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. and in addition to this sample application is crashes in device.

Any help will be appreciated.


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.

It is possible using internal android.jar( and hidden(@hide) API. Refer the below link:

How to programmatically create a new VPN interface with Android 4.0?

Need Your Help

How do I display an alert dialog on Android?

android android-dialog

I want to display a dialog/popup window with a message to the user that shows "Are you sure you want to delete this entry?" with one button that says 'Delete'. When Delete is touched, it should del...

radio Buttons and .attr('checked','checked') does NOT work in IE7

jquery internet-explorer-7 radio-button

Is there any way to get radio buttons checked upon appending in IE7?