How to check VPN connection status on Android ICS

前端 未结 4 2096
遥遥无期
遥遥无期 2021-02-05 23:51

I\'m trying to register receiver, that will check VPN status. I have tried this: Get VPN Connection status on Android but looks like it no longer works on ICS. I have checked an

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 00:45

    for (Enumeration en =
                 NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();
                if (intf.getName().contains("tun0") || intf.getName().contains("ppp0")) {
                    vpnInterface = intf;
                    break;
                }
            }
    

    For the VPNNetwork Interface

    for (Enumeration en =
                     vpnInterface.getInetAddresses(); en.hasMoreElements(); ) {
                    InetAddress address = en.nextElement();
                    if (!address.isLoopbackAddress()) {
                        String ip = address.getHostAddress();
                        break;
                    }
                }
    

    and the InetAddress

    Thats everything I know by the moment now

    To check if it's up etc. maybe

    if (vpnInterface.isUp())
    

    I do have implemented a code which calls itself after a serveral time and send a message to the ApplicationHandlers

提交回复
热议问题