本文整理匯總了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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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");
}
}
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}