Example usage for android.net.wifi WifiManager getScanResults

List of usage examples for android.net.wifi WifiManager getScanResults

Introduction

In this page you can find the example usage for android.net.wifi WifiManager getScanResults.

Prototype

public List<ScanResult> getScanResults() 

Source Link

Document

Return the results of the latest access point scan.

Usage

From source file:Main.java

public static List<ScanResult> getWifiScanResults(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManager.startScan() ? wifiManager.getScanResults() : null;
}

From source file:Main.java

public static void getScanWifiResults(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> wifiResults = wifiManager.getScanResults();
    for (ScanResult wifi : wifiResults) {
        //         LogUtil.log(TAG, Log.DEBUG, wifi.toString());
    }// www .  ja v  a  2s  . com

    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    //      LogUtil.log(TAG, Log.DEBUG, TelephonyManager.PHONE_TYPE_GSM + "----" + tm.getPhoneType());
    List<NeighboringCellInfo> cellResults = tm.getNeighboringCellInfo();
    for (NeighboringCellInfo cell : cellResults) {
        //         LogUtil.log(TAG, Log.DEBUG, cell.getCid() + "-" + cell.getLac() + "-" + cell.getRssi() + "-" + cell.getPsc()
        //               + "-" + cell.getNetworkType());
    }

    //      LogUtil.log(TAG, Log.DEBUG, getProviderName(context).getText());
}

From source file:Main.java

public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ScanResult scanResult = null;/* w  w  w  .j  av a 2  s . c om*/
    boolean f = wifiManager.startScan();
    if (!f) {
        getScanResultsByBSSID(context, bssid);
    }
    List<ScanResult> list = wifiManager.getScanResults();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            scanResult = list.get(i);
            if (scanResult.BSSID.equals(bssid)) {
                break;
            }
        }
    }
    return scanResult;
}

From source file:org.wahtod.wififixer.ui.LocalNetworksLoader.java

private List<WFScanResult> getNetworks(Context context) {
    WifiManager wm = AsyncWifiManager.getWifiManager(context);

    if (wm.isWifiEnabled()) {
        List<WFScanResult> scanned = WFScanResult.fromScanResultArray(wm.getScanResults());
        if (scanned != null) {
            Collections.sort(scanned, new SortBySignal());
            return scanned;
        }/*from ww  w.jav  a  2 s  . co  m*/
    }
    return new ArrayList<WFScanResult>();
}

From source file:ru.glesik.wifireminders.AddReminderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_reminder);
    // Show the Up button in the action bar.
    setupActionBar();/*w  w w  .  j a v  a2 s .com*/
    // Prepare receiver for AP scan results.
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    scanReceiver = new BroadcastReceiver() {
        public void onReceive(Context c, Intent i) {
            // Scan results are available.
            WifiManager w = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
            // Handle scan results.
            scanResultHandler(w.getScanResults());
        }
    };
    registerReceiver(scanReceiver, intentFilter);
}

From source file:ru.glesik.wifireminders.AlarmService.java

@Override
public void onCreate() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    scanReceiver = new BroadcastReceiver() {
        public void onReceive(Context c, Intent i) {
            // Scan results are available.
            WifiManager w = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
            // Handle scan results.
            scanResultHandler(w.getScanResults());
        }/*from w ww .j  a v  a 2 s. co m*/
    };
    registerReceiver(scanReceiver, intentFilter);
}

From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WPairingFragment.java

/**
 * Check Wifi./*from   w w w. j  a  v a  2  s.  c  o m*/
 */
private void searchWifi() {
    final WifiManager wifiManager = getWifiManager();
    if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
        mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                List<ScanResult> results = wifiManager.getScanResults();
                if (results.size() == 0) {
                    return;
                }
                mSSID.setText(results.get(0).SSID);
            }
        };
        getActivity().registerReceiver(mReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    }
    wifiManager.startScan();
}

From source file:com.example.multi_ndef.frag_wifi.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_wifi, container, false);

    mSpinner = (Spinner) v.findViewById(R.id.spinner);
    mSpinner.setOnItemSelectedListener(this);

    mEditText1 = (EditText) v.findViewById(R.id.editText1);
    fr = (CNFCInterface) getActivity().getApplication();

    WifiManager wifi;
    try {/*  w  ww.  j  ava  2 s.  c o  m*/
        wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);

        // Get WiFi status
        WifiInfo info = wifi.getConnectionInfo();
        // List available networks

        wifi.startScan();
        List<ScanResult> results;
        results = wifi.getScanResults();
        int array_length = results.size();
        int i = 0;
        String[] values = new String[array_length];
        for (ScanResult result : results) {
            values[i] = result.SSID;
            i = i + 1;
        }

        Set<String> set = new HashSet<String>();
        Collections.addAll(set, values);
        String[] uniques = set.toArray(new String[0]);
        int length = uniques.length;

        List<String> SpinnerArray = new ArrayList<String>();

        for (int i1 = 1; i1 < length; i1++) {
            SpinnerArray.add(uniques[i1]);
        }

        // Create an ArrayAdapter using the string array and a default

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),
                android.R.layout.simple_spinner_item, SpinnerArray);
        // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        mSpinner.setAdapter(adapter);

    } catch (Exception e) {
        Toast toast = Toast.makeText(getActivity().getApplicationContext(), "Turn on the wifi",
                Toast.LENGTH_SHORT);
        toast.show();

    }

    return v;
}

From source file:org.wahtod.wififixer.ui.KnownNetworksFragment.java

private ArrayList<String> getKnownAPArray(Context context) {

    WifiManager wm = AsyncWifiManager.getWifiManager(context);

    List<ScanResult> scanResults = wm.getScanResults();
    /*/*from   w ww .  j a  va  2  s .com*/
     * Catch null if scan results fires after wifi disabled or while wifi is
    * in intermediate state
    */
    if (scanResults == null) {
        return null;
    }
    /*
     * Iterate the known networks over the scan results, adding found known
    * networks.
    */
    ArrayList<String> known_in_range = new ArrayList<String>();
    for (ScanResult sResult : scanResults) {
        /*
         * Add known networks in range
        */

        if (knownnetworks.contains(sResult.SSID)) {
            /*
             * Add result to known_in_range
            */
            known_in_range.add(sResult.SSID);
        }
    }

    return known_in_range;
}

From source file:fr.inria.ucn.collectors.NetworkStateCollector.java

@SuppressLint("NewApi")
@Override/*from w  ww  .  j  a v a2s  .  c om*/
public void onReceive(Context context, Intent intent) {
    long ts = System.currentTimeMillis();
    if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
        context.unregisterReceiver(this);
        try {
            JSONArray neighs = new JSONArray();
            WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            for (ScanResult r : wm.getScanResults()) {
                JSONObject o = new JSONObject();
                o.put("frequency", r.frequency);
                o.put("level", r.level);
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    o.put("timestamp", r.timestamp);
                }
                o.put("bssid", r.BSSID);
                o.put("ssid", r.SSID);
                neighs.put(o);
            }

            JSONObject wifi = new JSONObject();
            wifi.put("list", neighs);
            Helpers.sendResultObj(context, "wifi_neigh", ts, wifi);

        } catch (JSONException jex) {
            Log.w(Constants.LOGTAG, "failed to create json object", jex);
        }
        // this will clean the CPU lock too if running on the bg
        Helpers.releaseWifiLock();
    }
}