Overall access can be mobile data on the Internet get IP also can WiFi access method
public static String Getphoneip () { try {for (enumeration<networkinterface> en = Networkinterface.getnetworkinterfaces (); En.hasmoreelements ();) { NetworkInterface intf = En.nextelement (); for (enumeration<inetaddress> enumipaddr = intf.getinetaddresses (); enumipaddr.hasmoreelements ();) { InetAddress inetaddress = Enumipaddr.nextelement (); if (!inetaddress.isloopbackaddress () && inetaddress instanceof inet4address) { //if (! Inetaddress.isloopbackaddress () && inetaddress //instanceof inet6address) { return Inetaddress.gethostaddress (). toString ();}}} catch (Exception e) { } return "127.0.0.1";}
WiFi Get IP method
Private String inttoip (int IP) {return (IP & 0xFF) + "." + ((IP >> 8) & 0xFF) + "." + ((IP >> +) & 0xFF) + "." + ((IP >> +) & 0xFF);} Private String GetIP () {//Get WIFI service Wifimanager Wifimanager = (wifimanager) getsystemservice (context.wifi_service);// Determine if WiFi is turned on if (wifimanager.iswifienabled ()) {//wifimanager.setwifienabled (true); Wifiinfo wifiinfo = Wifimanager.getconnectioninfo (); int ipAddress = Wifiinfo.getipaddress (); return Inttoip (ipAddress) ;} return "127.0.0.1";}
Android Gets the IP address of the device