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.odo.kcl.mobileminer.miner.MinerService.java

private void connectivityChanged() {
    String name = "None";
    ConnectivityManager manager = (ConnectivityManager) getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = manager.getActiveNetworkInfo();
    if (netInfo != null) {
        if (netInfo.getState() == NetworkInfo.State.CONNECTED) {
            switch (netInfo.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                wifiData = true;/*from   w  w  w.ja  v a  2 s.  com*/
                mobileData = false;
                if (!updating)
                    startUpdating();
                WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
                WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
                name = wifiInfo.getSSID();
                if (!networkName.equals(name)) {
                    wirelessData = new WifiData(wifiInfo);
                    MinerData helper = new MinerData(context);
                    helper.putWifiNetwork(helper.getWritableDatabase(), wirelessData, new Date());
                    helper.close();
                    networkName = name;
                    networkBroadcast();
                }
                startScan(); // Always scan when we've got WIFI.
                //Log.i("MinerService","CONNECTED: WIFI");
                break;
            case ConnectivityManager.TYPE_MOBILE:
                wifiData = false;
                mobileData = true;
                if ("goldfish".equals(Build.HARDWARE)) {
                    if (!updating)
                        startUpdating();
                } else {
                    updating = false;
                }

                // https://code.google.com/p/android/issues/detail?id=24227
                //String name; Cursor c;
                //c = this.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null);
                //name = c.getString(c.getColumnIndex("name"));
                TelephonyManager telephonyManager = ((TelephonyManager) this
                        .getSystemService(Context.TELEPHONY_SERVICE));
                name = telephonyManager.getNetworkOperatorName();
                if (!networkName.equals(name)) {
                    MinerData helper = new MinerData(context);
                    helper.putMobileNetwork(helper.getWritableDatabase(), telephonyManager, new Date());
                    helper.close();
                    networkName = name;
                    networkBroadcast();
                }
                //startScan();
                //Log.i("MinerService","CONNECTED MOBILE: "+name);
                break;
            default:
                //Log.i("MinerService",netInfo.getTypeName());
                break;
            }
        } else {
            scanning = false;
        }
    } else {
        scanning = false;
        networkName = "null";
    }

}

From source file:com.ifoer.util.NetPOSPrinter.java

public int printPic(Bitmap bmp) {
    WifiManager wifi_service = (WifiManager) this.mContext.getSystemService("wifi");
    DhcpInfo dhcpinfo = wifi_service.getDhcpInfo();
    WifiInfo wifi_info = wifi_service.getConnectionInfo();
    if (wifi_info != null && wifi_info.getSSID() != null && !wifi_info.getSSID().startsWith("X-431PRINTER")) {
        return PRINT_NOT_CONNECT;
    }/* w w  w . java  2  s. c om*/
    this.serverAddress = dhcpinfo.serverAddress;
    try {
        this.wifiSocket = new Socket(Formatter.formatIpAddress(this.serverAddress), PRINT_PORT);
        this.dos = new DataOutputStream(this.wifiSocket.getOutputStream());
        this.in = new DataInputStream(this.wifiSocket.getInputStream());
    } catch (UnknownHostException e1) {
        e1.printStackTrace();
    } catch (IOException e12) {
        e12.printStackTrace();
    }
    if (this.dos == null || this.in == null) {
        return PRINT_NOT_CONNECT;
    }
    byte[] data = new byte[3];
    data[0] = (byte) 27;
    data[ERROR_PRINT_JAM] = (byte) 51;
    try {
        this.dos.write(data, 0, data.length);
        data[0] = (byte) 0;
        data[ERROR_PRINT_JAM] = (byte) 0;
        data[ERROR_PRINT_WILL_NO_PAPER] = (byte) 0;
    } catch (IOException e122) {
        e122.printStackTrace();
    }
    byte[] escj = new byte[3];
    escj[0] = (byte) 27;
    escj[ERROR_PRINT_JAM] = (byte) 74;
    int i = 3;
    byte[] esccheck = new byte[] { (byte) 29, (byte) 114, (byte) 73 };
    byte[] escBmp = new byte[5];
    escBmp[0] = (byte) 27;
    escBmp[ERROR_PRINT_JAM] = (byte) 42;
    escBmp[ERROR_PRINT_WILL_NO_PAPER] = SmileConstants.TOKEN_LITERAL_NULL;
    escBmp[3] = (byte) (bmp.getWidth() % KEYRecord.OWNER_ZONE);
    escBmp[ERROR_PRINT_NO_PAPER] = (byte) (bmp.getWidth() / KEYRecord.OWNER_ZONE);
    for (int i2 = 0; i2 < (bmp.getHeight() / 24) + ERROR_PRINT_JAM; i2 += ERROR_PRINT_JAM) {
        try {
            this.dos.write(escBmp, 0, escBmp.length);
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (int j = 0; j < bmp.getWidth(); j += ERROR_PRINT_JAM) {
            for (int k = 0; k < 24; k += ERROR_PRINT_JAM) {
                if ((i2 * 24) + k < bmp.getHeight()) {
                    if (Color.red(bmp.getPixel(j, (i2 * 24) + k)) == 0) {
                        int i3 = k / ERROR_PRINT_ACTUATOR_FAULT;
                        data[i3] = (byte) (data[i3]
                                + ((byte) (ERROR_PRINT_HEAD_OVERHEATING >> (k % ERROR_PRINT_ACTUATOR_FAULT))));
                    }
                }
            }
            try {
                this.dos.write(data, 0, data.length);
                data[0] = (byte) 0;
                data[ERROR_PRINT_JAM] = (byte) 0;
                data[ERROR_PRINT_WILL_NO_PAPER] = (byte) 0;
            } catch (IOException e2) {
                e2.printStackTrace();
            }
        }
        try {
            if (i2 % 10 == 0) {
                this.dos.write(esccheck);
                if (this.in.readByte() == null) {
                    this.dos.write(escj, 0, escj.length);
                }
            } else {
                this.dos.write(escj, 0, escj.length);
            }
        } catch (IOException e22) {
            e22.printStackTrace();
        }
    }
    i = 3;
    byte[] escf = new byte[] { (byte) 29, (byte) 122, (byte) 49 };
    i = 3;
    byte[] esck = new byte[] { (byte) 27, (byte) 74, (byte) 64 };
    try {
        this.dos.write(escf);
        this.dos.write(esck);
        this.result = this.in.readByte();
        try {
            this.dos.close();
            this.in.close();
        } catch (IOException e222) {
            e222.printStackTrace();
        }
        return this.result;
    } catch (IOException e3) {
        return PRINT_NOT_CONNECT;
    }
}

From source file:com.melchor629.musicote.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    // Set the user interface layout for this Activity
    // The layout file is defined in the project res/layout/main.xml file
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*  ww w. j  a  v  a2 s  .  com*/
    appContext = getApplicationContext();

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.mainLayout);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark,
            R.color.colorGrey600);
    final ListView list = (ListView) findViewById(android.R.id.list);
    list.setOnScrollListener(new ListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            boolean enable = false;
            if (list != null && list.getChildCount() > 0) {
                // check if the first item of the list is visible
                boolean firstItemVisible = list.getFirstVisiblePosition() == 0;
                // check if the top of the first item is visible
                boolean topOfFirstItemVisible = list.getChildAt(0).getTop() == 0;
                // enabling or disabling the refresh layout
                enable = firstItemVisible && topOfFirstItemVisible;
            }
            swipeRefreshLayout.setEnabled(enable);
        }
    });
    getActionBar().setIcon(R.drawable.ic_launcher);
    getActionBar().setDisplayUseLogoEnabled(true);

    // La app prueba en busca de la direccin correcta
    WifiManager mw = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = mw.getConnectionInfo();
    String SSID = wi.getSSID();
    Log.i("MainActivity", "Wifi conectado: " + SSID + " " + (SSID != null ? SSID.equals("Madrigal") : ""));
    if (SSID == null) {
        SSID = "";
        Toast.makeText(this, getString(R.string.no_wifi), Toast.LENGTH_LONG).show();
    }
    if (SSID.equals("Madrigal") || SSID.contains("Madrigal")
            || System.getProperty("os.version").equals("3.4.67+")) {
        MainActivity.HOST = "192.168.1.133";
    } else {
        MainActivity.HOST = "reinoslokos.no-ip.org";
    }
    Log.i("MainActivity", "HOST: " + HOST);

    //Deletes the notification if remains (BUG)
    NotificationManager mn = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Reproductor.a == -1)
        mn.cancel(1);
    mn.cancel(3);

    //Revisa la base de datos
    DB mDbHelper = new DB(getBaseContext());
    SQLiteDatabase db = mDbHelper.getWritableDatabase();

    //Actualizacin de la lista
    if (mDbHelper.isNecesaryUpgrade(db) && Utils.HostTest(HOST) == 200)
        async();
    else
        cursordb(db);

    db.close();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

From source file:devbox.com.br.minercompanion.ProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);


    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo.isConnected()) {
        final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
        final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        if (connectionInfo != null && !(connectionInfo.getSSID().equals(""))) {
            //if (connectionInfo != null && !StringUtil.isBlank(connectionInfo.getSSID())) {
            routerName = connectionInfo.getSSID();
        }/*from   w w  w  .j a  v a 2  s  .com*/
    }

    sensorCounter = new SensorCounter(3000, 3000);
    sensorCounter.start();

    Intent intent = getIntent();

    if(intent != null) {
        matricula = intent.getStringExtra("MATRICULA");

        TextView textView = (TextView) findViewById(R.id.textView);

        textView.setText("Matrcula: " + matricula);

        sensors = new Sensors(matricula, routerName.replace("\"",""));
    }

    /* Get a SensorManager instance */
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    ListView listView = (ListView) findViewById(R.id.listView);
    profileListAdapter = new ProfileListAdapter(this, strings);
    listView.setAdapter(profileListAdapter);

    profileListAdapter.addItem("Conectado ao servidor!");
}

From source file:net.helff.wificonnector.WifiConnectivityService.java

/**
 * Used to cut of quotes in the SSID. This is a broken behavior of Android 4.2
 * //from  ww  w . j a  va  2  s . c  o m
 * @param wi the WifiInfo
 * @return The SSID of the network without quotes or an empty string
 */
protected String normalizeSSID(WifiInfo wi) {
    String ssid = "";

    if (wi != null) {
        ssid = wi.getSSID();
        if (ssid != null && ssid.startsWith("\"") && ssid.endsWith("\"")) {
            ssid = ssid.substring(1, ssid.length() - 1);
        }
    }

    return ssid;
}

From source file:mobisocial.musubi.ui.NearbyActivity.java

private void doCheckin() {
    WifiInfo wifi = mWifiManager.getConnectionInfo();
    String myWifiName = wifi.getSSID();
    if (myWifiName == null) {
        /**//from ww w .  j  a va 2 s.c  om
         * TODO:
         * Depending on desired outcome, either help them get on wifi
         * or try connecting to gps server, etc.
         */
        toast("No wifi network available.");
        return;
    }

    String myWifiId = wifi.getBSSID();
    String myIp = formatIp(wifi.getIpAddress());
    String myWifiFingerprint = Util.computeWifiFingerprint(mWifiManager.getScanResults());

    if (DBG)
        Log.d(TAG, "Checking in to " + myWifiName + "...");
    JSONObject loc = new JSONObject();
    try {
        loc.put(DbContactAttributes.ATTR_WIFI_SSID, myWifiName);
        if (myWifiId != null) {
            loc.put(DbContactAttributes.ATTR_WIFI_BSSID, myWifiId);
        }
        if (myIp != null) {
            loc.put(DbContactAttributes.ATTR_LAN_IP, myIp);
        }
        loc.put(DbContactAttributes.ATTR_WIFI_FINGERPRINT, myWifiFingerprint);
    } catch (JSONException e) {
        // Impossible json exception
    }

    //XXX killed for now
    //mMusubi.getAppFeed().postObj(new MemObj("locUpdate", loc));
    //toast("Checked in to '" + myWifiName + "'.");
}

From source file:org.pidome.client.phone.services.SystemService.java

private void setHome() {
    if (prefs != null) {
        if (prefs.getBoolPreference("wifiConnectHomeEnabled", false)) {
            ConnectivityManager connManager = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
            if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                if (connectionInfo != null) {
                    String SSID = connectionInfo.getSSID();
                    String BSSID = connectionInfo.getBSSID();
                    if (SSID != null && BSSID != null) {
                        if (SSID.equals(prefs.getStringPreference("wifiConnectSSID",
                                java.util.UUID.randomUUID().toString()))
                                && BSSID.equals(prefs.getStringPreference("wifiConnectBSSID",
                                        java.util.UUID.randomUUID().toString()))) {
                            if (this.system != null) {
                                try {
                                    system.getClient().getEntities().getPresenceService().setPresence(1);
                                } catch (EntityNotAvailableException ex) {
                                    Logger.getLogger(SystemService.class.getName()).log(Level.SEVERE, null, ex);
                                }/* w w w .ja v a2  s  .  c  om*/
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:riddimon.android.asianetautologin.CredentialActivity.java

private void refreshNetworkSpinnerIfNecessary() {
    if (mSsids != null && mSsids.size() != 0)
        return;//  ww w. j a va 2s.c o  m
    //get wifi networks
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> lwc = wm.getConfiguredNetworks();
    WifiInfo wi = wm.getConnectionInfo();
    String wssid = null;
    if (wi != null && wm.isWifiEnabled()) {
        String ssid = wi.getSSID();
        if (!TextUtils.isEmpty(ssid)) {
            wssid = ssid.replace("\"", "");
        }
    }

    mSsids = new ArrayList<String>();
    int selection = 0;
    if (lwc != null) {
        int i = -1;
        for (WifiConfiguration wc : lwc) {
            i++;
            String ssid = TextUtils.isEmpty(wc.SSID) ? "" : wc.SSID.replace("\"", "");
            mSsids.add(ssid);
            if (!TextUtils.isEmpty(wssid) && ssid.equals(wssid)) {
                selection = i;
            }
        }
    }

    mSsid.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, mSsids));
    if (mSsids != null && mSsids.size() > 0) {
        mSsid.setSelection(selection);
    }
}

From source file:syncthing.android.service.ServiceSettings.java

boolean isConnectedToWhitelistedNetwork() {
    Set<String> whitelist = allowedWifiNetworks();
    if (whitelist == null || whitelist.isEmpty()) {
        Timber.d("No whitelist found");
        return true;
    }/* w  w w .j  a  v  a  2  s.c  o  m*/
    WifiInfo info = wm.getConnectionInfo();
    if (info == null) {
        Timber.w("WifiInfo was null");
        return true;
    }
    String ssid = info.getSSID();
    if (ssid == null) {
        Timber.w("SSID was null");
        return true;
    }
    if (whitelist.contains(ssid)) {
        Timber.d("Found %s in whitelist", ssid);
        return true;
    } else {
        return false;
    }
}