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


Java WifiManager.getScanResults方法代码示例

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


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

示例1: onReceive

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent)
{
    WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    String name = wifiInfo.getSSID();
    for(ScanResult result: wifiMgr.getScanResults()){
        WifiApListProvider.this.output(new WifiAp(result, name.equals(result.SSID)));
    }
    WifiApListProvider.this.finish();
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:12,代码来源:WifiApListProvider.java

示例2: getCipherType

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static WifiCipherType getCipherType(Context context, String ssid) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);

    List<ScanResult> list = wifiManager.getScanResults();

    for (ScanResult scResult : list) {

        if (!StringUtils.isEmpty(scResult.SSID) && scResult.SSID.equals(ssid)) {
            String capabilities = scResult.capabilities;

            if (!StringUtils.isEmpty(capabilities)) {

                if (capabilities.contains("WPA")
                        || capabilities.contains("wpa")) {
                    LogUtils.i("wpa");
                    return WifiCipherType.WIFICIPHER_WPA;
                } else if (capabilities.contains("WEP")
                        || capabilities.contains("wep")) {
                    LogUtils.i("wep");
                    return WifiCipherType.WIFICIPHER_WEP;
                } else {
                    LogUtils.i("no");
                    return WifiCipherType.WIFICIPHER_NOPASS;
                }
            }
        }
    }
    return WifiCipherType.WIFICIPHER_INVALID;
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:31,代码来源:WifiAutoConnectManager.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: wifiConnection

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static boolean wifiConnection(Context context, String wifiSSID, String password) {
    WifiManager wifi = (WifiManager) context.getSystemService("wifi");
    String strQuotationSSID = "\"" + wifiSSID + "\"";
    WifiInfo wifiInfo = wifi.getConnectionInfo();
    if (wifiInfo != null && (wifiSSID.equals(wifiInfo.getSSID()) || strQuotationSSID.equals(wifiInfo.getSSID()))) {
        return true;
    }
    List<ScanResult> scanResults = wifi.getScanResults();
    if (scanResults == null || scanResults.size() == 0) {
        return false;
    }
    for (int nAllIndex = scanResults.size() - 1; nAllIndex >= 0; nAllIndex--) {
        String strScanSSID = ((ScanResult) scanResults.get(nAllIndex)).SSID;
        if (wifiSSID.equals(strScanSSID) || strQuotationSSID.equals(strScanSSID)) {
            WifiConfiguration config = new WifiConfiguration();
            config.SSID = strQuotationSSID;
            config.preSharedKey = "\"" + password + "\"";
            config.status = 2;
            return wifi.enableNetwork(wifi.addNetwork(config), false);
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:NetworkHelper.java

示例5: getWifiListNearby

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public List<Map<String, String>> getWifiListNearby() {
    List<Map<String, String>> arrayList = new ArrayList();
    if (this.a == null) {
        return arrayList;
    }
    WifiManager wifiManager = (WifiManager) this.a.getSystemService("wifi");
    if (wifiManager == null) {
        return arrayList;
    }
    List<ScanResult> scanResults = wifiManager.getScanResults();
    if (scanResults == null) {
        return arrayList;
    }
    for (ScanResult scanResult : scanResults) {
        Map hashMap = new HashMap();
        hashMap.put("wifiMac", scanResult.BSSID == null ? "" : scanResult.BSSID);
        hashMap.put("ssid", scanResult.SSID);
        hashMap.put("rssi", scanResult.level);
        arrayList.add(hashMap);
    }
    return arrayList;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:LocationInfo.java

示例6: getAvailableAPList

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static ArrayList<String> getAvailableAPList(Context context) {
    ArrayList<String> apList = new ArrayList<String>();
    try {
        isNtutccAround = false;
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> scanResults = wifiManager.getScanResults();
        for (ScanResult result : scanResults) {
            apList.add(result.SSID + ":" + result.level + "dBm");
            if (result.SSID.equals("ntutcc")) {
                isNtutccAround = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apList;
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:19,代码来源:WifiUtility.java

示例7: getWifiConfiguration

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * 获取要连接的wifi节点各个配置选项的加密类型
 *
 * @param ssid
 * @return wifiConfiguration
 */
public static WifiConfiguration getWifiConfiguration(WifiManager manager, String ssid, String
        password) {
    WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.SSID = "\"" + ssid + "\"";

    List<ScanResult> list = manager.getScanResults();
    for (ScanResult scResult : list) {
        if (ssid.equals(scResult.SSID)) {
            String capabilities = scResult.capabilities;
            LogUtils.i("capabilities=" + capabilities);
            if (capabilities.contains("WEP") || capabilities.contains("wep")) {
                wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
                wifiConfiguration.preSharedKey = "\"" + password + "\"";
                LogUtils.i("wep");
            } else if (capabilities.contains("WPA") || capabilities.contains("wpa")) {
                wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
                wifiConfiguration.preSharedKey = "\"" + password + "\"";
                LogUtils.i("wpa");
            } else {
                wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
                LogUtils.i("none");
            }
        }
    }
    return wifiConfiguration;
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:33,代码来源:NetworkConnectionUtils.java

示例8: onReceive

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    wifimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> results = wifimanager.getScanResults();
    for (ScanResult result : results) {
        Log.d("WifiScanReceiver",
                String.format("\n%s (%s) %dMHz %ddBm", result.SSID, result.capabilities,
                        result.frequency, result.level));
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:11,代码来源:WifiScanReceiver.java

示例9: 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

示例10: connectToAP

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public int connectToAP(Context context, String networkSSID, String networkPasskey) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    for (ScanResult result : wifiManager.getScanResults()) {
        if (result.SSID.equals(networkSSID)) {
            String securityMode = getScanResultSecurity(result);
            WifiConfiguration wifiConfiguration = createAPConfiguration(networkSSID, networkPasskey, securityMode);
            int res = wifiManager.addNetwork(wifiConfiguration);
            Log.d(TAG, "# addNetwork returned " + res);
            boolean b = wifiManager.enableNetwork(res, true);
            Log.d(TAG, "# enableNetwork returned " + b);
            wifiManager.setWifiEnabled(true);
            boolean changeHappen = wifiManager.saveConfiguration();
            if (res != -1 && changeHappen) {
                Log.d(TAG, "# Change happen: " + networkSSID);
            } else {
                Log.d(TAG, "# Change NOT happen");
            }
            return res;
        }
    }
    return -1;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:23,代码来源:WifiUtil.java

示例11: X

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static JSONArray X(Context context) {
    try {
        if (a(context, "android.permission.INTERNET") && a(context, "android.permission" +
                ".ACCESS_NETWORK_STATE")) {
            WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
            if (wifiManager != null) {
                List scanResults = wifiManager.getScanResults();
                if (scanResults != null && scanResults.size() > 0) {
                    Collections.sort(scanResults, new s());
                    JSONArray jSONArray = new JSONArray();
                    int i = 0;
                    while (i < scanResults.size() && i < 10) {
                        ScanResult scanResult = (ScanResult) scanResults.get(i);
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("bs", scanResult.BSSID);
                        jSONObject.put("ss", scanResult.SSID);
                        jSONArray.put(jSONObject);
                        i++;
                    }
                    return jSONArray;
                }
            }
            return null;
        }
        Log.e("MtaSDK", "can not get the permisson of android.permission.INTERNET");
        return null;
    } catch (Throwable th) {
        Log.e("MtaSDK", "isWifiNet error", th);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:31,代码来源:r.java

示例12: getWifiLevel

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static int getWifiLevel(Context context, String BSSID) {
    try {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> scanResults = wifiManager.getScanResults();
        for (ScanResult result : scanResults) {
            if (result.BSSID.equals(BSSID)) {
                return result.level;
            }
        }
    } catch (Exception e) {
    }
    return -100;
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:15,代码来源:WifiUtility.java

示例13: onHandleIntent

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    client = new FindWiFiImpl(getApplicationContext());

    // Getting all the value passed from previous Fragment
    eventName = intent.getStringExtra("event");
    userName = intent.getStringExtra("userName");
    groupName = intent.getStringExtra("groupName");
    serverName = intent.getStringExtra("serverName");
    locationName = intent.getStringExtra("locationName");
    Long timeStamp = System.currentTimeMillis()/1000;

    // getting all wifi APs and forming data payload
    try {
        mWifiData = new WifiData();
        mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
        JSONArray wifiResultsArray = new JSONArray();
        List<ScanResult> mResults = mWifiManager.getScanResults();

        for (ScanResult result : mResults) {
            JSONObject wifiResults = new JSONObject();
            if (shouldLog(result)) {
                wifiResults.put("mac", result.BSSID);
                wifiResults.put("rssi", result.level);
                wifiResultsArray.put(wifiResults);
            }
        }
        wifiFingerprint = new JSONObject();
        wifiFingerprint.put("group", groupName);
        wifiFingerprint.put("username", userName);
        wifiFingerprint.put("location", locationName);
        wifiFingerprint.put("time", timeStamp);
        wifiFingerprint.put("wifi-fingerprint", wifiResultsArray);
        Log.d(TAG, String.valueOf(wifiFingerprint));

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    // Send the packet to server
    sendPayload(eventName, serverName, wifiFingerprint);

}
 
开发者ID:uncleashi,项目名称:find-client-android,代码行数:44,代码来源:WifiIntentReceiver.java

示例14: onCreate

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

    // Get the stored sort order
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    int sortOrderOrdinal = prefs.getInt(PREF_WIFI_SORT_ORDER, SortOrder
            .NONE.ordinal());
    if (sortOrderOrdinal >= 0 && sortOrderOrdinal < SortOrder.values()
            .length) {
        sortOrder = SortOrder.values()[sortOrderOrdinal];
    }

    // Make a BroadcastReceiver to get the scan results
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final WifiManager wifi = (WifiManager) getSystemService
                    (Context.WIFI_SERVICE);
            int state = wifi.getWifiState();
            if (state != WifiManager.WIFI_STATE_ENABLED) {
                Utils.errMsg(WifiActivity.this, "WiFi is not enabled");
                return;
            }
            List<ScanResult> scanResults = wifi.getScanResults();
            // Make the ArrayList
            mNetworks = new ArrayList<WifiNetwork>(scanResults.size());
            for (ScanResult scanResult : scanResults) {
                mNetworks.add(new WifiNetwork(scanResult));
            }
            // Sort the arrays list
            Collections.sort(mNetworks);
            // Set the adapter
            mNetworkListdapter = new NetworkListAdapter();
            setListAdapter(mNetworkListdapter);
        }
    };
    registerReceiver(mReceiver, new IntentFilter(
            WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));


    // Call refresh to set the contents
    refresh();
}
 
开发者ID:KennethEvans,项目名称:Misc,代码行数:46,代码来源:WifiActivity.java

示例15: 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


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