2

I'm using the ConnectivityManager to check the network interfaces type in this manner:

NetworkInfo info = cm.getActiveNetworkInfo();
if(info.getType() == ConnectivityManager.TYPE_WIFI)
    return "WIFI";

My problem is that I have to use API 19, while the TYPE_VPN value was introduced only in API 21.

How can I check if the interface is a VPN?

JJ Ab
  • 492
  • 4
  • 15
  • You will get that TYPE_VPN if you use the android system to connect to it, otherwise you will not right? – Nanoc Nov 26 '15 at 09:30
  • What? That value is part of the ConnectivityManager only in later APIs than what I have to use. – JJ Ab Nov 26 '15 at 09:34
  • 1
    I mean Android doesnt know if you are connected to a VPN if its managed by an external app. – Nanoc Nov 26 '15 at 09:36
  • It can know what interfaces are up, give me a list of these interfaces, and then I can enumarate and query them using the code I wrote above. VPN can be one of the interfaces and I need a way to identify that the interface is of type VPN. – JJ Ab Nov 26 '15 at 09:38
  • So you dont have the constant but what is returning the connectivity manager? in that case? can you check it? – Nanoc Nov 26 '15 at 09:41
  • The connectivity manager is the same one as the regular in android: http://developer.android.com/reference/android/net/ConnectivityManager.html#TYPE_VPN – JJ Ab Nov 26 '15 at 10:34
  • Then if getType == 17 its VPN – Nanoc Nov 26 '15 at 10:36
  • ok.. is it possible that the getType won't return 17 since maybe that value was also introduced in API 21? (I'm not sure if it was, but just to be sure) – JJ Ab Nov 26 '15 at 10:39
  • That is what i was asking, connect to vpn and test it to see what value is returning. – Nanoc Nov 26 '15 at 10:41
  • Check this out : https://stackoverflow.com/questions/28386553/check-if-a-vpn-connection-is-active-in-android – nnyerges Aug 25 '20 at 15:47

0 Answers0