Check VPN Status

More block (vpn)

Create a more block named "vpn" and add following code into it add curly bracket before and after


public boolean vpn() {

    String iface = "";

    try {

        for (java.net.NetworkInterface networkInterface : Collections.list(java.net.NetworkInterface.getNetworkInterfaces())) {

            if (networkInterface.isUp())

                iface = networkInterface.getName();

                Log.d("DEBUG", "IFACE NAME: " + iface);

            if ( iface.contains("tun") || iface.contains("ppp") || iface.contains("pptp")) {

                return true;

            }

        }

    } catch (Exception e1) {

        e1.printStackTrace();

    }

    return false;

}

Add following code where you want to check:


if (vpn()) {

// vpn is connected

}

else

{

//vpn not connected

}