Android IPアドレス取得（自分用メモ

機種差分は考えてない。。。

```
    public static void getIpAddress() {
        mIPv4Address = "0.0.0.0";
        mIPv6Address = "0:0:0:0:0:0:0:0";
        mWifiIPv4Address = "0.0.0.0";
        mWifiIPv6Address = "0:0:0:0:0:0:0:0";
        mBluetoothIPv4Address = "0.0.0.0";
        mBluetoothIPv6Address = "0:0:0:0:0:0:0:0";
        mVpnIPv4Address = "0.0.0.0";
        mVpnIPv6Address = "0:0:0:0:0:0:0:0";

        Enumeration<NetworkInterface> enumeration;
        try {
            enumeration = NetworkInterface.getNetworkInterfaces();
            while(enumeration.hasMoreElements()) {
                NetworkInterface netIf = enumeration.nextElement();
                Enumeration<InetAddress> ipAddrs = netIf.getInetAddresses();

                while(ipAddrs.hasMoreElements()) {
                    InetAddress inetAddress = ipAddrs.nextElement();
                    if(!inetAddress.isLoopbackAddress() && netIf.isUp()) {
                        String networkInterfaceName = netIf.getName();
                        setIPAddress(inetAddress, networkInterfaceName);
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }

    private static void setIPAddress(InetAddress inetAddress, String interfaceName) {
        String ipAddress = inetAddress.getHostAddress();
        if (inetAddress instanceof Inet4Address) {
            if (interfaceName.contains("rmnet0")) {
                mIPv4Address = ipAddress;
            } else if (interfaceName.contains("wlan0")) {
                mWifiIPv4Address = ipAddress;
            } else if (interfaceName.contains("bt-pan")) {
                mBluetoothIPv4Address = ipAddress;
            } else if (interfaceName.contains("ppp0")) {
                mVpnIPv4Address = ipAddress;
            }

        } else if (inetAddress instanceof Inet6Address) {
            if (interfaceName.contains("rmnet0")) {
                mIPv6Address = ipAddress.replace("%"+interfaceName, "");
            } else if (interfaceName.contains("wlan0")) {
                mWifiIPv6Address = ipAddress.replace("%"+interfaceName, "");
            } else if (interfaceName.contains("bt-pan")) {
                mBluetoothIPv6Address = ipAddress.replace("%"+interfaceName, "");
            } else if (interfaceName.contains("ppp0")) {
                mVpnIPv6Address = ipAddress.replace("%"+interfaceName, "");
            }
        }
    }

    public static String getIPv4Address() {
        return mIPv4Address;
    }

    public static String getIPv6Address() {
        return mIPv6Address;
    }

    private static String mIPv4Address;
    private static String mIPv6Address;

    public static String getWifiIPv4Address() {
        return mWifiIPv4Address;
    }

    public static String getWifiIPv6Address() {
        return mWifiIPv6Address;
    }

    private static String mWifiIPv4Address;
    private static String mWifiIPv6Address;

    public static String getBtIPv4Address() {
        return mBluetoothIPv4Address;
    }

    public static String getBtIPv6Address() {
        return mBluetoothIPv6Address;
    }
    private static String mBluetoothIPv4Address;
    private static String mBluetoothIPv6Address;

    public static String getVpnIPv4Address() {
        return mVpnIPv4Address;
    }

    public static String getVpnIPv6Address() {
        return mVpnIPv6Address;
    }

    private static String mVpnIPv4Address;
    private static String mVpnIPv6Address;
```