2

I am developing an android application that has to be connected to a VPN through an external application.

I am currently using the following code to check the open connections, and in case you do not have a VPN enabled, create an intent to the application to connect the VPN.

int countVPN =0;
try {
    for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
        if (networkInterface.isUp()){
            if (networkInterface.getName().equals("tun0")){
                countVPN++;
            }
        }
    }
} catch (Exception ex) {

}

if (countVPN==0){
    Intent launchIntent = getPackageManager().getLaunchIntentForPackage(appVPN);
    if (launchIntent != null) {
            startActivity(launchIntent);
    }
}

Once the VPN is connected, it can only be closed by opening a notification and clicking on disconnect.

The configuration that we have in the phone does not allow the user to access the notifications.

Is there any way to close the VPN connection from my application?

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
Fernando
  • 349
  • 2
  • 6
  • 21

0 Answers0