-1

I have a third party VPN app on my non-rooted Android 4.4 device, and want to write a background service to monitor the VPN connection and alert the user if the VPN connection is on.

1 Answers1

2

Check this:

public static boolean isVpnConnectionActive(){
    List<String> networks = new ArrayList<>();

    try {
        for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
            if (networkInterface.isUp()){
                networks.add(networkInterface.getName());
            }
        }
    } catch (Exception ignored) {
    }

    return networks.contains("tun") || networks.contains("ppp") || networks.contains("pptp");
}
Hamed
  • 5,867
  • 4
  • 32
  • 56