Method to pass username and password in VpnService.Builder

给你一囗甜甜゛ 提交于 2019-12-03 11:06:29

问题


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.


回答1:


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.




回答2:


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

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



来源:https://stackoverflow.com/questions/11471465/method-to-pass-username-and-password-in-vpnservice-builder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!