Detect behind VPN in android

前端 未结 5 904
半阙折子戏
半阙折子戏 2021-01-05 22:49

How to detect programatically if traffic is going through VPN without using intent to connect to VPNService. Is there some system call?

5条回答
  •  别那么骄傲
    2021-01-05 22:57

    This works :

    private boolean checkVPN() {
        ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
        return cm.getNetworkInfo(ConnectivityManager.TYPE_VPN).isConnectedOrConnecting();
    }
    

提交回复
热议问题