I am working on an Android application that should start an OpenVPN Connect session automatically when necessary.
How can I programmatically connect and disconnect vpn connections using the openvpn connect android application in conjunction with intentions?
Edit: In the meantime, I found this approach - it works for me:
private void startVPN() { Intent openVPN = new Intent("android.intent.action.VIEW"); openVPN.setPackage("net.openvpn.openvpn"); openVPN.setClassName("net.openvpn.openvpn", net.openvpn.openvpn.OpenVPNClient"); openVPN.putExtra("net.openvpn.openvpn.AUTOSTART_PROFILE_NAME", "10.10.10.10 [profilename]"); startActivityForResult(openVPN, 0); }
This launches the OpenVPN Connect application and uses the profile name for automatic connection.
If the application successfully goes into the background,
Is there a way to do this completely in the background?
Stopping a VPN connection does everything in the background.
private void stopVPN() { Intent openVPN = new Intent("android.intent.action.VIEW"); openVPN.setPackage("net.openvpn.openvpn"); openVPN.setClassName("net.openvpn.openvpn", "net.openvpn.openvpn.OpenVPNDisconnect"); startActivityForResult(openVPN, 0); }
android android-intent openvpn
composit
source share