Example usage for android.net.wifi WifiInfo getSSID

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

Introduction

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

Prototype

public String getSSID() 

Source Link

Document

Returns the service set identifier (SSID) of the current 802.11 network.

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;
    }//w  w w  . jav a  2  s .com
    return new WiFiConnection(WiFiUtils.convertSSID(wifiInfo.getSSID()), wifiInfo.getBSSID(),
            WiFiUtils.convertIpAddress(wifiInfo.getIpAddress()), wifiInfo.getLinkSpeed());
}

From source file:org.wso2.emm.agent.services.DeviceNetworkStatus.java

private String getWifiSSID() {
    if (wifiManager != null) {
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    }/* www. j av  a  2 s.co m*/
    return null;
}

From source file:com.example.android.nfcprovisioning.ProvisioningValuesLoader.java

private void loadSystemValues(HashMap<String, String> values) {
    Context context = getContext();
    putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
            "com.example.android.deviceowner");
    putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_LOCALE,
            context.getResources().getConfiguration().locale.toString());
    putIfMissing(values, DevicePolicyManager.EXTRA_PROVISIONING_TIME_ZONE, TimeZone.getDefault().getID());
    if (!values.containsKey(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Activity.WIFI_SERVICE);
        WifiInfo info = wifiManager.getConnectionInfo();
        values.put(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID, trimSsid(info.getSSID()));
    }/* ww  w  .  j  a v a 2  s  .c  om*/
}

From source file:com.mstar.tv.tvplayer.philips.option.OptionFirstFragment.java

private boolean isWifiConnected() {
    WifiManager wifiManager = getWifiManager();
    // wifi is disabled
    if (!wifiManager.isWifiEnabled()) {
        return false;
    }// ww w .j a v a2s. co m

    // wifi have not connected
    WifiInfo info = wifiManager.getConnectionInfo();
    if (info == null || info.getSSID() == null || info.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID) {
        return false;
    }

    return true;
}

From source file:de.taxilof.UulmLoginAgent.java

/**
 * fetch the ssid of the wifi network//  w  w w  . j  a v  a  2s.com
 * 
 * @return ip
 */
private String getSsid() {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String ssid = null;
    if (wifiInfo != null) {
        ssid = wifiInfo.getSSID();
    }
    if (ssid != null) {
        return ssid.replace("\"", ""); // because .getSSID() sucks...
    } else {
        return "";
    }
}

From source file:com.lge.helloFriendsCamera.MainActivity.java

public boolean checkIsConnectedToDevice() {
    WifiManager wifimanager;//from  www  .  j a va  2 s. co m
    wifimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    WifiInfo info = wifimanager.getConnectionInfo();

    String ssid = info.getSSID();
    Log.d("HERE", " ssid = " + ssid);

    if (ssid.contains(".OSC")) {
        return true;
    } else {
        return false;
    }
}

From source file:net.micode.fileexplorer.ServerControlActivity.java

/**
 * This will be called by the static UiUpdater whenever the service has
 * changed state in a way that requires us to update our UI. We can't use
 * any myLog.l() calls in this function, because that will trigger an
 * endless loop of UI updates.//  w  w  w. j  ava  2 s.  c  o  m
 */
public void updateUi() {
    myLog.l(Log.DEBUG, "Updating UI", true);

    WifiManager wifiMgr = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE);
    int wifiState = wifiMgr.getWifiState();
    WifiInfo info = wifiMgr.getConnectionInfo();
    String wifiId = info != null ? info.getSSID() : null;
    boolean isWifiReady = FTPServerService.isWifiEnabled();

    setText(R.id.wifi_state, isWifiReady ? wifiId : getString(R.string.no_wifi_hint));
    ImageView wifiImg = (ImageView) mRootView.findViewById(R.id.wifi_state_image);
    wifiImg.setImageResource(isWifiReady ? R.drawable.wifi_state4 : R.drawable.wifi_state0);

    boolean running = FTPServerService.isRunning();
    if (running) {
        myLog.l(Log.DEBUG, "updateUi: server is running", true);
        // Put correct text in start/stop button
        // Fill in wifi status and address
        InetAddress address = FTPServerService.getWifiIp();
        if (address != null) {
            String port = ":" + FTPServerService.getPort();
            ipText.setText(
                    "ftp://" + address.getHostAddress() + (FTPServerService.getPort() == 21 ? "" : port));

        } else {
            // could not get IP address, stop the service
            Context context = mActivity.getApplicationContext();
            Intent intent = new Intent(context, FTPServerService.class);
            context.stopService(intent);
            ipText.setText("");
        }
    }

    startStopButton.setEnabled(isWifiReady);
    TextView startStopButtonText = (TextView) mRootView.findViewById(R.id.start_stop_button_text);
    if (isWifiReady) {
        startStopButtonText.setText(running ? R.string.stop_server : R.string.start_server);
        startStopButtonText.setCompoundDrawablesWithIntrinsicBounds(
                running ? R.drawable.disconnect : R.drawable.connect, 0, 0, 0);
        startStopButtonText.setTextColor(running ? getResources().getColor(R.color.remote_disconnect_text)
                : getResources().getColor(R.color.remote_connect_text));
    } else {
        if (FTPServerService.isRunning()) {
            Context context = mActivity.getApplicationContext();
            Intent intent = new Intent(context, FTPServerService.class);
            context.stopService(intent);
        }

        startStopButtonText.setText(R.string.no_wifi);
        startStopButtonText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        startStopButtonText.setTextColor(Color.GRAY);
    }

    ipText.setVisibility(running ? View.VISIBLE : View.INVISIBLE);
    instructionText.setVisibility(running ? View.VISIBLE : View.GONE);
    instructionTextPre.setVisibility(running ? View.GONE : View.VISIBLE);
}

From source file:org.sociotech.fishification.ui.MainActivity.java

/**
 * Checks for WiFi connection and if SSID is allowed.
 *
 * @return If Wifi connection check was successful.
 *///from ww  w.j  av a2  s  . c o  m
private boolean checkWifiConnection() {
    if (!m_wifiCheck) {
        return true;
    }

    ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo.State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (wifi == NetworkInfo.State.CONNECTED) {
        if (m_wifiSSIDs.length == 0) {
            return true;
        }

        WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();

        String ssid = wifiInfo.getSSID().replace("\"", "").trim();
        for (String s : m_wifiSSIDs) {
            if (ssid.equalsIgnoreCase(s.trim())) {
                return true;
            }
        }

        Toast.makeText(this, "Not connected to allowed WiFi zones.", Toast.LENGTH_LONG);
        return false;
    }

    Toast.makeText(this, "No WiFi connection available.", Toast.LENGTH_LONG);
    return false;
}

From source file:nacho.tfg.blepresencetracker.MyFirebaseInstanceIDService.java

/**
 * Persist token to third-party servers.
 *
 * Modify this method to associate the user's FCM InstanceID token with any server-side account
 * maintained by your application.//w ww .  ja v  a  2 s .c o m
 *
 * @param token The new token.
 */
private void sendRegistrationToServer(String token) {
    // Add custom implementation, as needed.
    Intent intent = new Intent(ACTION_SHOW_TOKEN);
    intent.putExtra("token", token);
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

        @Override
        protected Boolean doInBackground(String... params) {
            String data = params[0];
            String ip = "192.168.4.1";
            int port = 7777;
            try {
                Socket socket = new Socket(ip, port);
                while (!socket.isConnected()) {

                }

                OutputStream out = socket.getOutputStream();
                PrintWriter output = new PrintWriter(out);

                output.println(data);
                output.flush();
                out.close();
                output.close();

                socket.close();
            } catch (SocketException e) {
                e.printStackTrace();
                return false;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            if (result) {
                SharedPreferences settings = PreferenceManager
                        .getDefaultSharedPreferences(MyFirebaseInstanceIDService.this);
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean(getString(R.string.registration_id_sent), true);
                editor.commit();
            } else {
                SharedPreferences settings = PreferenceManager
                        .getDefaultSharedPreferences(MyFirebaseInstanceIDService.this);
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean(getString(R.string.registration_id_sent), false);
                editor.commit();
            }
        }
    };

    // Change wifi network to "NodeMCU WiFi"

    String ssid = "";
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()) == NetworkInfo.DetailedState.CONNECTED) {
        ssid = wifiInfo.getSSID();
    }

    if (!ssid.equals("NodeMCU WiFi")) {
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(), getString(R.string.toast_connect_NodeMCU),
                        Toast.LENGTH_LONG).show();

            }
        });

    }
}