当前位置: 首页>>代码示例>>Java>>正文


Java WifiManager.startScan方法代码示例

本文整理汇总了Java中android.net.wifi.WifiManager.startScan方法的典型用法代码示例。如果您正苦于以下问题:Java WifiManager.startScan方法的具体用法?Java WifiManager.startScan怎么用?Java WifiManager.startScan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.startScan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: provide

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected void provide() {

    WifiManager wifiMgr = (WifiManager) this.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);

    if(wifiMgr.isWifiEnabled()) {
        Log.e("wifi","enabled");
        this.getContext().registerReceiver(this.wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        wifiMgr.startScan();
    }
    else{
        Log.e("wifi","not enabled");
        this.finish();
    }

}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:17,代码来源:WifiApListProvider.java

示例2: refresh

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * Starts a scan for networks.
 */
private void refresh() {
    try {
        setListAdapter(mNetworkListdapter);
        if (mNetworkListdapter != null) {
            // Clear the data to indicate we are waiting
            mNetworkListdapter.clear();
            // Refresh the View so it shows
            mNetworkListdapter.notifyDataSetChanged();
        }
        WifiManager wifiManager = (WifiManager) getSystemService(Context
                .WIFI_SERVICE);
        wifiManager.startScan();
    } catch (Exception ex) {
        Utils.excMsg(this, "Error starting network scan", ex);
    }
}
 
开发者ID:KennethEvans,项目名称:Misc,代码行数:20,代码来源:WifiActivity.java

示例3: getScanResultsByBSSID

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ScanResult scanResult = null;
    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;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:19,代码来源:NetUtils.java

示例4: doInBackground

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\"";
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

    WifiManager wifiManager = (WifiManager) getBaseContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.addNetwork(conf);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
        wifiManager.startScan();
    }

    int netId = wifiManager.addNetwork(conf);
    wifiManager.disconnect();
    wifiManager.enableNetwork(netId, true);
    wifiManager.reconnect();

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), "Joined to " + networkSSID, Toast.LENGTH_SHORT).show();
            System.out.println("SUCCESS ");
        }
    });
    return null;
}
 
开发者ID:yuvaraj119,项目名称:WifiChatSharing,代码行数:29,代码来源:MainActivity.java

示例5: onCreate

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    setContentView(R.layout.activity_bind_device_two);

    AndroidBug54971Workaround.assistActivity(findViewById(android.R.id.content));
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= 20) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.bar_color));
    }

    llBack = (LinearLayout) findViewById(R.id.ll_back);
    llBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
    TextView btnSure = (TextView) findViewById(R.id.tvEditSure);
    btnSure.setVisibility(View.INVISIBLE);

    TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
    tvTitle.setText(R.string.find_devices);

    txtTime = (TextView) findViewById(R.id.txtTime);
    txtTime.setText("" + scanTime);
    progressBar = (ColorfulRingProgressView) findViewById(R.id.spv);
    new Thread(new MyThread()).start();
    type = getIntent().getIntExtra("type", 0);
    if (type == 1) {
        ((TextView) findViewById(R.id.txtTitle)).setText(R.string.add_device_two_title2);
        mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        mWifiManager.startScan();
        //搜索网络并加入
        WlanScan();
    } else {
        BluetoothScan();
    }
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:41,代码来源:BindDeviceSearchActivity.java

示例6: connect

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public void connect(String ssid, String pwd, WiFiStaConnectCallback callback){
    if(callback == null){
        return;
    }
    mCallback = callback;
    mSSID = ssid;
    mPWD = pwd;
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = "\"" + mSSID + "\"";
    if(pwd.equals("")){
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    }
    else{
        config.preSharedKey = "\"" + mPWD + "\"";
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    }
    config.status = WifiConfiguration.Status.ENABLED;
    config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    if(!wifiManager.isWifiEnabled()){
        wifiManager.setWifiEnabled(true);
    }
    wifiManager.startScan();
    int networkId = wifiManager.addNetwork(config);
    wifiManager.disconnect();
    wifiManager.enableNetwork(networkId, true);
    wifiManager.reconnect();
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:29,代码来源:WifiSta.java

示例7: scanWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public List<ScanResult> scanWifi(){
    lstWifi.clear();
    final WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    if (wifi.isWifiEnabled() == false)
    {
        wifi.setWifiEnabled(true);
    }

    mContext.registerReceiver(new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context c, Intent intent)
        {
            lstWifi = wifi.getScanResults();;
        }
    }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    wifi.startScan();

    int i = 0;
    while(i < 10){
        i++;
        try {
            Thread.sleep(1000);
        }catch (Exception e){

        }
    }
    return lstWifi;
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:30,代码来源:WifiSta.java

示例8: onRequestPermissionsResult

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == 0x12345) {
        for (int grantResult : grantResults) {
            if (grantResult != PackageManager.PERMISSION_GRANTED) {
                return;
            }
        }
        WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        boolean wasEnabled = myWifiManager.isWifiEnabled();
        if (!wasEnabled)
            myWifiManager.setWifiEnabled(true);
        if (myWifiManager.isWifiEnabled()) {
            if (myWifiManager.startScan()) {
                // List available APs
                Log.d("pras", "this inside scan");
                List<ScanResult> scans = myWifiManager.getScanResults();
                Log.d("pras", "" + (scans == null));
                Log.d("pras", "" + scans.isEmpty());
                if (scans != null && !scans.isEmpty()) {
                    for (ScanResult scan : scans) {
                        int level = WifiManager.calculateSignalLevel(scan.level, 20);
                        //Other code
                        Log.d("wifi", level + "this");
                    }
                } else {
                    Log.d("pras", "this inside else");
                }
            }
        }

    }

}
 
开发者ID:PrasannaNatarajan,项目名称:Interrobang,代码行数:35,代码来源:MainActivity.java

示例9: startScan

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static boolean startScan(Context context, BroadcastReceiver reciever) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    context.registerReceiver(reciever, new IntentFilter(
            WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    boolean result = wifiManager.startScan();
    return result;
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:9,代码来源:WifiUtility.java

示例10: WifiScanReceiver

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public WifiScanReceiver(CrossfadePageTransformer crossfadePageTransformer, SetupActivity activity) {
    this.crossfadePageTransformer = crossfadePageTransformer;
    wifiManager = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    crossfadePageTransformer.setWifiNetworks(getWifiNetworks());
    wifiManager.startScan();
}
 
开发者ID:ProjektMedInf,项目名称:WiFiSDCryptoLocker,代码行数:7,代码来源:WifiScanReceiver.java

示例11: getWifiScanResults

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static List<ScanResult> getWifiScanResults(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManager.startScan() ? wifiManager.getScanResults() : null;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:5,代码来源:NetUtils.java

示例12: getCurrentWifiScanResult

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static List<ScanResult> getCurrentWifiScanResult(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiManager.startScan();
    return wifiManager.getScanResults();
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:6,代码来源:NetworkUtils.java

示例13: connectWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
private void connectWifi() {
  info("Connecting to WiFi");

  final WifiManager manager = (WifiManager) getApplicationContext()
      .getSystemService(Context.WIFI_SERVICE);

  if (!manager.isWifiEnabled()) {
    info("Enabling WiFi");
    manager.setWifiEnabled(true);
  }

  if (!manager.startScan()) {
    info("Could not start a WiFi scan ...");
  }

  final List<android.net.wifi.ScanResult> list = manager.getScanResults();
  for (final android.net.wifi.ScanResult result : list) {
    if (result.SSID != null
        && result.SSID.startsWith("LGR105")
        && result.SSID.endsWith(".OSC")
        ) {
      info("Found WiFi candidate: " + result.capabilities);

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);

      String networkSSID = result.SSID;
      String networkPass = prefs.getString("wifipass", "");

      WifiConfiguration conf = new WifiConfiguration();
      conf.SSID = "\"" + networkSSID + "\"";
      conf.preSharedKey = "\"" + networkPass + "\"";
      conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

      final int networkId = manager.addNetwork(conf);
      if (networkId != -1) {
        manager.disconnect();
        manager.enableNetwork(networkId, true);
        manager.saveConfiguration();
      }

      info("WiFi: Connected!");
    }
  }
}
 
开发者ID:mariobodemann,项目名称:osc,代码行数:45,代码来源:MainActivity.java

示例14: WifiStrength

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public List<Map.Entry<String, Double>> WifiStrength(){
        WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        boolean wasEnabled = myWifiManager.isWifiEnabled();
        if (!wasEnabled)
            myWifiManager.setWifiEnabled(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Log.d("pras","inside permission");
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 0x12345);
        }

        if (myWifiManager.isWifiEnabled()) {
            if (myWifiManager.startScan()) {
                // List available APs
                Log.d("pras", "inside scan");
                List<ScanResult> scans = myWifiManager.getScanResults();
                Log.d("pras", "" + (scans == null));
                Log.d("pras", "" + scans.isEmpty());

                //int topThree = 3;
                if (scans != null && !scans.isEmpty()) {
                    int i=0;
                    for (ScanResult scan : scans) {
                        Double level = (double)scan.level;
                        Log.d("frequency",scan.frequency + "");
                        //Other code
                        Log.d("pras", scan.SSID + " : " + scan.level);
//                        if(topThree!=0)

//                        Log.d("pras",scan.SSID);


                        wifiDetails.put(scan.BSSID,level);
                    }
                } else {
                    Log.d("pras", "inside else");
                }
            }
        }


        Set<Map.Entry<String, Double>> set = wifiDetails.entrySet();
        List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(set);
        Collections.sort( list, new Comparator<Map.Entry<String, Double>>()
        {
            public int compare( Map.Entry<String, Double> o1, Map.Entry<String, Double> o2 )
            {
                return (o2.getValue()).compareTo( o1.getValue() );
            }
        } );
        for(int tt = 0; tt<5; tt++)
            toastText+= list.get(tt).getKey()+ " : " + list.get(tt).getValue()   + "\n";
        for(Map.Entry<String, Double> entry:list){
            Log.d("Pras",entry.getKey()+" ==== "+entry.getValue());
        }

        return list;
    }
 
开发者ID:PrasannaNatarajan,项目名称:Interrobang,代码行数:59,代码来源:MainActivity.java

示例15: startScan

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static void startScan(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiManager.startScan();
}
 
开发者ID:hoanglm4,项目名称:RxAndroidTBP,代码行数:5,代码来源:NetworkUtil.java


注:本文中的android.net.wifi.WifiManager.startScan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。