Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically connect and disconnect vpn connections by using android's "openvpn connect" app in combination with intents?

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);
}
like image 391
composit Avatar asked Mar 02 '15 18:03

composit


1 Answers

OpenVPN's official Android client can be invoked through AIDL. There's an entire sample app available, with source code. It even has a relatively friendly license.

like image 77
323go Avatar answered Oct 01 '22 06:10

323go