android.net.wifi.WifiManager.startScan()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(337)

本文整理了Java中android.net.wifi.WifiManager.startScan()方法的一些代码示例,展示了WifiManager.startScan()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.startScan()方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:startScan

WifiManager.startScan介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

wifi.startScan();

代码示例来源:origin: cSploit/android

@Override
public boolean onOptionsItemSelected(MenuItem item){
  if(item.getItemId() == R.id.scan){
    if(mMenu != null){
      MenuItem menuScan = mMenu.findItem(R.id.scan);
      MenuItemCompat.setActionView(menuScan, new ProgressBar(getActivity()));
    }
    mWifiManager.startScan();
    mStatusText.setText(getString(R.string.scanning));
    mScanning = true;
    return true;
  }
  if(item.getItemId() == android.R.id.home){
    onBackPressed();
    return true;
  } else
    return super.onOptionsItemSelected(item);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void startScan_shouldNotThrowException() {
 assertThat(wifiManager.startScan()).isTrue();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void startScan() throws Exception {
 // By default startScan() succeeds.
 assertThat(wifiManager.startScan()).isTrue();
 shadowOf(wifiManager).setStartScanSucceeds(true);
 assertThat(wifiManager.startScan()).isTrue();
 shadowOf(wifiManager).setStartScanSucceeds(false);
 assertThat(wifiManager.startScan()).isFalse();
}

代码示例来源:origin: facebook/facebook-android-sdk

private List<WifiScanResult> getActiveScanResults()
    throws ScannerException{
  List<WifiScanResult> wifiScanResults = null;
  try {
    if (Validate.hasChangeWifiStatePermission(context)) {
      registerBroadcastReceiver();
      boolean isScanStarted = wifiManager.startScan();
      if (isScanStarted) {
        try {
          synchronized (scanLock) {
            scanLock.wait(params.getWifiScanTimeoutMs());
          }
        } catch (InterruptedException e) {
          // ignore
        }
        wifiScanResults = getCachedScanResults();
      }
    }
  } catch (Exception e) {
    // ignore
  } finally {
    unregisterBroadcastReceiver();
  }
  return wifiScanResults;
}

代码示例来源:origin: cSploit/android

mScanning = true;
mWifiManager.startScan();

代码示例来源:origin: stackoverflow.com

IntentFilter i = new IntentFilter(); 
i.addAction (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); 
registerReceiver(new BroadcastReceiver(){ 
   public void onReceive(Context c, Intent i){ 
   // Code to execute when SCAN_RESULTS_AVAILABLE_ACTION event occurs 
   WifiManager w = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); 
   myScanResultHandler(w.getScanResults()); // your method to handle Scan results
   if (ScanAsFastAsPossible) w.startScan(); // relaunch scan immediately
   else { /* Schedule the scan to be run later here */}
   } 
  }, i ); 

  // Launch  wifiscanner the first time here (it will call the broadcast receiver above)
  WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
  boolean a = wm.startScan();

代码示例来源:origin: mayubao/KuaiChuan

/**
 * wifi扫描
 */
public void startScan(){
  mWifiManager.startScan();
  mScanResultList = mWifiManager.getScanResults();
  mWifiConfigurations = mWifiManager.getConfiguredNetworks();
}

代码示例来源:origin: TeamFatCat/Easy_Transfer

/**
 * 扫描热点
 *
 * @return
 */
public void ScanWifiAp() {
  mWifiManager.startScan();
}

代码示例来源:origin: stackoverflow.com

WifiManager wifi= (WifiManager) getSystemService(Context.WIFI_SERVICE);

wifi.startScan();
// get list of the results in object format ( like an array )
List<ScanResult> results = wifi.getScanResults();`

// loop that goes through list
for (ScanResult result : results) {
 Toast.makeText(this, result.SSID + " " + result.level,
 Toast.LENGTH_SHORT).show();
}

代码示例来源:origin: pwittchen/NetworkEvents

@Override public void onReceive(Context context, Intent intent) {
 // We need to start WiFi scan after receiving an Intent
 // in order to get update with fresh data as soon as possible
 WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
 wifiManager.startScan();
 onPostReceive();
}

代码示例来源:origin: stackoverflow.com

String connectivity_context = Context.WIFI_SERVICE;
      final WifiManager wifi = (WifiManager) getSystemService(connectivity_context);  
if (wifi.isWifiEnabled()) {
            wifi.startScan();
          }

代码示例来源:origin: JackWHLiu/jackknife

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

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private void scanResults() {
  try {
    if (wifiManager.startScan()) {
      List<ScanResult> scanResults = wifiManager.getScanResults();
      cache.add(scanResults);
    }
  } catch (Exception e) {
    // critical error: do not die
  }
}

代码示例来源:origin: stackoverflow.com

WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);

// To scan only 2.4 GHz Frequency band

// true, if this needs to be remembered

wm.setFrequencyBand(2, false);

// Start scan.

wm.startScan();

// To get the frequency band used.

int band = wm.getFrequncyBand();

代码示例来源:origin: JackWHLiu/jackknife

public void startScan() {
  mWifiManager.startScan();
  mScanResults = mWifiManager.getScanResults();
  mWifiConfigurations = mWifiManager.getConfiguredNetworks();
}

代码示例来源:origin: microg/android_external_UnifiedNlpApi

private synchronized boolean scanWiFis() {
  if (state == State.DISABLED)
    return false;
  if (wifiManager.isWifiEnabled() || isScanAlwaysAvailable()) {
    state = State.SCANNING;
    wifiManager.startScan();
    return true;
  }
  return false;
}

代码示例来源:origin: 18Gray/CommonUtils

/**
 * 扫描所有可用网络
 * @param context
 */
public void startScan(Context context)
{
  wifiManager.startScan();
  // 得到扫描结果
  mWifiList = wifiManager.getScanResults();
  // 得到配置好的网络连接
  mWifiConfiguration = wifiManager.getConfiguredNetworks();
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private void withWiFiManager() {
  when(wifiManager.isWifiEnabled()).thenReturn(false);
  when(wifiManager.startScan()).thenReturn(true);
  when(wifiManager.getScanResults()).thenReturn(scanResults);
  when(wifiManager.getConnectionInfo()).thenReturn(wifiInfo);
  when(wifiManager.getConfiguredNetworks()).thenReturn(configuredNetworks);
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private void verifyWiFiManager() {
  verify(wifiManager).isWifiEnabled();
  verify(wifiManager).setWifiEnabled(true);
  verify(wifiManager).startScan();
  verify(wifiManager).getScanResults();
  verify(wifiManager).getConnectionInfo();
  verify(wifiManager).getConfiguredNetworks();
}

相关文章