I'm working on an android app that should start an OpenVPN Connect session automatically when needed.
How can I programmatically connect and disconnect vpn connections by using android's "openvpn connect" app in combination with intents ?
Edit: Meanwhile 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 starts the "OpenVPN Connect" app and uses the profilename to do an auto-connect.
If successfull the app goes to background by itself.
Is there even a way to do this completly in background ?
Stopping the VPN-connection does everything in 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);
}