4

I'm making an app which wants to detect VPN Connection. My Question is I want to Detect VPN Connection, If VPN is Connected I don't want to allow the user to use my app, In case VPN is off I want to allow the user to use my app.

Before Asking This question I read this Documents VPNService VPNStatus

But I can't get Solution. If anyone knows the solution, Please Share with me.

Thanks in Advance

Ramesh
  • 280
  • 1
  • 7
  • 19

1 Answers1

5

This is works for me: Tested from API 16 to 23:

 List<String> networkList = new ArrayList<>();
try {
    for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
        if (networkInterface.isUp())
            networkList.add(networkInterface.getName());
    }
} catch (Exception ex) {
    Timber.d("isVpnUsing Network List didn't received");
}

return networkList.contains("tun0");
bugfreerammohan
  • 1,471
  • 1
  • 7
  • 22