Home » Android » How to Create VPN Profile and Connect to it in android Programmatically?

How to Create VPN Profile and Connect to it in android Programmatically?

Posted by: admin May 14, 2020 Leave a comment

Questions:

We are developing an Android app that needs to connect to a VPN. The problem that we have is that the users that are going to use this app, do not have any knowledge about Creating VPN profiles, to connect then to it, and then to connect to the app etc.

So, we are obligated to find a way when our Application starts, to connect to the VPN (we will hard code all the requirements needed). But the problem is that we searched on the internet and we couldn’t find anything :(.

I wanted to ask you, is there anyway to Create a VPN Profile programmatically, and then Connect to it after the creation?

The VPN Profile that we need (VPN profile data that wee need to fill):

Name: ________

Type: IPSec Xauth PSK

Servber address: __________

IPSec identifier: __________

IPSec pre-shared key: ___________

Username: ______________

Password: ______________

Thank you in advance 😀

How to&Answers:

To programmatically add VPN profiles, there doesn’t seem to be any Android API to do this. There is a VPNService and VPNService.Builder classes that will allow you to create and connect a VPN within your application.

I believe what you’re looking to do though is add a new entry in the Android settings VPN list. This can be done via Samsung KNOX for devices that support KNOX via this KNOX API: https://seap.samsung.com/api-references/android-premium/reference/com/sec/enterprise/knox/GenericVpnPolicy.html