2

I am trying to find a solution to control vpn connections within an android app I build. I could find the following results so far:

  • Since Android version 2.3.x it is not possible to control android's vpn client through intents.
  • VpnService provides methods to build your own vpn solutions from scratch and comes without any common protocols.

I found a solution to programmatically connect and disconnect vpn connections by using android's "openvpn connect" app in combination with intents I send from my app. Is there any possibility to add new openvpn profiles programmatically (through intents)? User interaction like accepting or agreeing to adding new profiles is ok.

ashiaka
  • 3,994
  • 8
  • 32
  • 45

2 Answers2

2
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.setComponent(new ComponentName("net.openvpn.openvpn","net.openvpn.openvpn.OpenVPNAttachmentReceiver"));
    intent.setDataAndType(Uri.parse(file_path), "application/x-openvpn-profile");
    startActivity(intent);
Anitha Manikandan
  • 1,160
  • 7
  • 19
  • Could i just use that to open a "*.opvn" file as profile (what if the profile already exists?) - my point: i don't know if openvpn is installed on the phone, i don't know if the profile is set or not, so i'd like to call an Intent to start openvpn and try to call for the profile that is in the file, if not then add it first – SammuelMiranda Jul 21 '21 at 19:32
1

I am not sure if OpenVPN Connect has any but OpenVPN for Android has an external API that allows you to do this. (See doc/README.txt and the example project)

plaisthos
  • 6,255
  • 6
  • 35
  • 63