Example usage for android.net.wifi WifiInfo getIpAddress

List of usage examples for android.net.wifi WifiInfo getIpAddress

Introduction

In this page you can find the example usage for android.net.wifi WifiInfo getIpAddress.

Prototype

public int getIpAddress() 

Source Link

Usage

From source file:com.vrem.wifianalyzer.wifi.scanner.Transformer.java

protected WiFiConnection transformWifiInfo(WifiInfo wifiInfo) {
    if (wifiInfo == null || wifiInfo.getNetworkId() == -1) {
        return WiFiConnection.EMPTY;
    }//  ww  w  . j  a  va 2 s .  c  o  m
    return new WiFiConnection(WiFiUtils.convertSSID(wifiInfo.getSSID()), wifiInfo.getBSSID(),
            WiFiUtils.convertIpAddress(wifiInfo.getIpAddress()), wifiInfo.getLinkSpeed());
}

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.HandsetFragment.java

private void displayIpAddress() {
    WifiManager wifiManager = (WifiManager) mApplication.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    String ipaddress = null;//from   w  w w  .  j  a v  a 2  s .com
    if (info != null && info.getNetworkId() > -1) {
        int i = info.getIpAddress();
        String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff,
                i >> 24 & 0xff);
        mLine1.setText(mHttpServer.isHttpsEnabled() ? "https://" : "http://");
        mLine1.append(ip);
        mLine1.append(":" + mHttpServer.getHttpPort());
        mLine2.setText("rtsp://");
        mLine2.append(ip);
        mLine2.append(":" + mRtspServer.getPort());
        streamingState(0);
    } else if ((ipaddress = Utilities.getLocalIpAddress(true)) != null) {
        mLine1.setText(mHttpServer.isHttpsEnabled() ? "https://" : "http://");
        mLine1.append(ipaddress);
        mLine1.append(":" + mHttpServer.getHttpPort());
        mLine2.setText("rtsp://");
        mLine2.append(ipaddress);
        mLine2.append(":" + mRtspServer.getPort());
        streamingState(0);
    } else {
        streamingState(2);
    }

}

From source file:net.majorkernelpanic.spydroid.ui.HandsetFragment.java

@Override
public void onStart() {
    super.onStart();

    // Print version number
    Context mContext = SpydroidApplication.getContext();
    try {/*w w w  . j  a v a  2  s .c om*/
        //mVersion.setText("v"+mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0 ).versionName);
        mVersion.setText("v0.1");
    } catch (Exception e) {
        mVersion.setText("v???");
    }

    displayIpAddress();

    WifiManager wifiManager = (WifiManager) SpydroidApplication.getContext()
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    int i = info.getIpAddress();
    final String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff,
            i >> 24 & 0xff);

    final String socketUrl = "http://192.168.1.10:3000/socket.io/1/";
    final Properties handshakeHeaders = new Properties();
    handshakeHeaders.setProperty("X-COLLAB-MEETINGID", "5161e2d4e83131372e000001");
    handshakeHeaders.setProperty("X-COLLAB-CONNECTION", ip + ":8086");

    mStartButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Log.i(TAG, "Attempting to connect to " + socketUrl);
                socket = new SocketIO(socketUrl, handshakeHeaders);

            } catch (MalformedURLException e) {
                Log.e(TAG, e.getMessage());
            }

            socket.connect(new IOCallback() {
                @Override
                public void onMessage(String data, IOAcknowledge ack) {
                    Log.i(TAG, data);
                    System.out.println("Server said: " + data);
                }

                @Override
                public void onError(SocketIOException socketIOException) {
                    System.out.println("an Error occured");
                    socketIOException.printStackTrace();
                    Log.e(TAG, socketIOException.getLocalizedMessage());

                }

                @Override
                public void onDisconnect() {
                    System.out.println("Connection terminated.");
                }

                @Override
                public void onConnect() {
                    System.out.println("Connection established");
                }

                @Override
                public void on(String event, IOAcknowledge ack, Object... args) {
                    System.out.println("Server triggered event '" + event + "'");
                }

                @Override
                public void onMessage(JSONObject arg0, IOAcknowledge arg1) {
                    Log.i(TAG, arg0.toString());
                }
            });
            /*
            //final String socketUrl = "http://192.168.1.10:3000/.io/1/?meeting=5161e2d4e83131372e000001&connection=" + ip + ":8086";
            final String socketUrl = "http://192.168.1.10:3000/socket.io/1/";
            List<BasicNameValuePair> extraHeaders = Arrays.asList(
                   new BasicNameValuePair("X-COLLAB-MEETINGID", "5161e2d4e83131372e000001"),
                   new BasicNameValuePair("X-COLLAB-CONNECTION", ip + ":8086" )
               );
            socket = new SocketIOClient(URI.create(socketUrl), new SocketIOClient.Handler() {
                @Override
                public void onConnect() {
            Log.d(TAG, "Connected!");
                }
                    
                @Override
                public void on(String event, JSONArray arguments) {
            Log.d(TAG, String.format("Got event %s: %s", event, arguments.toString()));
                }
                    
                @Override
                public void onJSON(JSONObject json) {
            Log.d(TAG, String.format("Got JSON Object: %s", json.toString()));
                }
                    
                @Override
                public void onMessage(String message) {
            Log.d(TAG, String.format("Got message: %s", message));
                }
                    
                @Override
                public void onDisconnect(int code, String reason) {
            Log.d(TAG, String.format("Disconnected! Code: %d Reason: %s", code, reason));
                }
                    
                @Override
                public void onError(Exception error) {
            Log.e(TAG, "Error!", error);
                }
            }, extraHeaders);
                    
                    
            socket.connect();
            */
        }
    });

    mStopButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            socket.emit("kill");
            socket.disconnect();
            socket = null;
        }
    });
}

From source file:tv.matchstick.demo.flingpic.FlingPicActivity.java

private void startWetServer(int port) {
    try {//  w w w  .  ja v  a  2  s .c o  m
        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();

        mIpAddress = intToIp(wifiInfo.getIpAddress());

        if (wifiInfo.getSupplicantState() != SupplicantState.COMPLETED) {
            new AlertDialog.Builder(this).setTitle("Error")
                    .setMessage("Please connect to a WIFI-network for starting the webserver.")
                    .setPositiveButton("OK", null).show();
            throw new Exception("Please connect to a WIFI-network.");
        }

        Log.e(TAG, "Starting server " + mIpAddress + ":" + port + ".");

        List<File> rootDirs = new ArrayList<File>();
        boolean quiet = false;
        Map<String, String> options = new HashMap<String, String>();
        rootDirs.add(new File(mRootDir).getAbsoluteFile());

        // mNanoHTTPD
        try {
            mNanoHTTPD = new SimpleWebServer(mIpAddress, port, rootDirs, quiet);
            mNanoHTTPD.start();
        } catch (IOException ioe) {
            Log.e(TAG, "Couldn't start server:\n" + ioe);
        }
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:net.olejon.spotcommander.AddComputerActivity.java

private void scanNetwork() {
    if (mNetworkScanTask != null && mNetworkScanTask.getStatus() == AsyncTask.Status.RUNNING) {
        mNetworkScanTask.cancel(true);/*from  ww w.  j  a v a2  s. com*/
    } else {
        final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

        if (wifiManager.isWifiEnabled()) {
            final WifiInfo wifiInfo = wifiManager.getConnectionInfo();

            final int wifiIpAddress = wifiInfo.getIpAddress();

            final String wifiSubnet = String.format("%d.%d.%d", (wifiIpAddress & 0xff),
                    (wifiIpAddress >> 8 & 0xff), (wifiIpAddress >> 16 & 0xff));

            if (wifiSubnet.equals("0.0.0")) {
                mTools.showToast(getString(R.string.add_computer_wifi_not_connected), 0);
            } else {
                mNetworkScanTask = new NetworkScanTask();
                mNetworkScanTask.execute(wifiSubnet);
            }
        } else {
            mTools.showToast(getString(R.string.add_computer_wifi_not_connected), 0);
        }
    }
}

From source file:net.majorkernelpanic.spydroid.ui.HandsetFragment.java

public void displayIpAddress() {
    WifiManager wifiManager = (WifiManager) SpydroidApplication.getContext()
            .getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiManager.getConnectionInfo();
    String ipaddress = null;//from  w w w  . j  a  v  a 2 s.  c  o m
    Log.d("SpydroidActivity", "getNetworkId " + info.getNetworkId());
    if (info != null && info.getNetworkId() > -1) {
        int i = info.getIpAddress();
        String ip = String.format(Locale.ENGLISH, "%d.%d.%d.%d", i & 0xff, i >> 8 & 0xff, i >> 16 & 0xff,
                i >> 24 & 0xff);
        mLine1.setText("http://");
        mLine1.append(ip);
        mLine1.append(":" + SpydroidApplication.sHttpPort);
        mLine2.setText("rtsp://");
        mLine2.append(ip);
        mLine2.append(":" + SpydroidApplication.sRtspPort);
        streamingState(0);
    } else if ((ipaddress = Utilities.getLocalIpAddress(true)) != null) {
        mLine1.setText("http://");
        mLine1.append(ipaddress);
        mLine1.append(":" + SpydroidApplication.sHttpPort);
        mLine2.setText("rtsp://");
        mLine2.append(ipaddress);
        mLine2.append(":" + SpydroidApplication.sRtspPort);
        streamingState(0);
    } else {
        mLine1.setText("HTTP://xxx.xxx.xxx.xxx:" + SpydroidApplication.sHttpPort);
        mLine2.setText("RTSP://xxx.xxx.xxx.xxx:" + SpydroidApplication.sHttpPort);
        streamingState(2);
    }
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static boolean isFast(int i) {
    WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();

    if (PreferenceManager.getDefaultSharedPreferences(mContext)
            .getString(org.sipdroid.sipua.ui.Settings.PREF_USERNAME + (i != 0 ? i : ""), "").equals("")
            || PreferenceManager.getDefaultSharedPreferences(mContext)
                    .getString(org.sipdroid.sipua.ui.Settings.PREF_SERVER + (i != 0 ? i : ""), "").equals(""))
        return false;
    if (wi != null) {
        if (!Sipdroid.release)
            Log.i("SipUA:", "isFastWifi() " + WifiInfo.getDetailedStateOf(wi.getSupplicantState()) + " "
                    + wi.getIpAddress());
        if (wi.getIpAddress() != 0
                && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR
                        || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED)
                || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTING) {
            on_wlan = true;/*  w  w w .j av a2 s  . c  o  m*/
            if (!on_vpn())
                return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_WLAN + (i != 0 ? i : ""),
                        org.sipdroid.sipua.ui.Settings.DEFAULT_WLAN);
            else
                return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_VPN + (i != 0 ? i : ""),
                        org.sipdroid.sipua.ui.Settings.DEFAULT_VPN);
        }
    }
    on_wlan = false;
    return isFastGSM(i);
}

From source file:net.mm2d.dmsexplorer.ServerListActivity.java

private InetAddress getWifiInetAddress() {
    final WifiInfo wi = ((WifiManager) getSystemService(WIFI_SERVICE)).getConnectionInfo();
    if (wi == null) {
        return null;
    }/*from w  w  w  .  ja v a2  s.  com*/
    try {
        return InetAddress.getByAddress(intToByteArray(wi.getIpAddress()));
    } catch (final UnknownHostException ignored) {
    }
    return null;
}

From source file:de.qspool.clementineremote.ui.ConnectActivity.java

/**
 * We couldn't connect to clementine. Inform the user
 *//*www.  ja v  a2  s .co  m*/
void noConnection() {
    // Do not display dialog if the activity has finished!
    if (this.isFinishing()) {
        return;
    }

    // Check if we have not a local ip
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();

    // Get the current wifi state
    if (!Utilities.onWifi()) {
        Utilities.ShowMessageDialog(this, R.string.connectdialog_error, R.string.wifi_disabled);
    } else if (!Utilities.ToInetAddress(ip).isSiteLocalAddress()) {
        Utilities.ShowMessageDialog(this, R.string.connectdialog_error, R.string.no_private_ip);
    } else {
        Utilities.ShowMessageDialog(this, getString(R.string.connectdialog_error),
                getString(R.string.check_ip, getString(R.string.clementine_version)), false);
    }
}