I am developing an WiFi app for the purpose of SMS forwarding .After turning on the WiFi button and open the app it will display the Ip address like and port number is 33300 in the corresponding edit boxes.The problem is when the app is open when i switch off the WiFi button it should display empty but still it display the IPAddress .Also again when i switch on the WiFi button it should display the IPAddress .How to check the continuously WiFi Address at the background and display it in the textbox

public class WifiFragment  extends Fragment {
EditText et_portnumber,et_IpAddress;
int port=33300;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) 

    View rootView = inflater.inflate(R.layout.wififragment, container, false);
    et_portnumber = (EditText) rootView.findViewById(R.id.etPortnumber);
    et_IpAddress= (EditText) rootView.findViewById(R.id.ipaddress);
    final String strgetIpdaddress= getIpAddress();
private String getIpAddress() {
    String ip = "";
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces   .nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ip =  inetAddress.getHostAddress() + "\n";
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        ip += "Something Wrong! " + e.toString() + "\n";
    return ip;


Related posts

Recent Viewed