當前位置: 首頁>>代碼示例>>Java>>正文


Java WifiManager類代碼示例

本文整理匯總了Java中android.net.wifi.WifiManager的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager類的具體用法?Java WifiManager怎麽用?Java WifiManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WifiManager類屬於android.net.wifi包,在下文中一共展示了WifiManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWifiSSID

import android.net.wifi.WifiManager; //導入依賴的package包/類
/**
 * Gets the SSID of the currently associated WiFi access point if there is one. Otherwise,
 * returns empty string.
 */
@CalledByNative
public static String getWifiSSID(Context context) {
    if (context == null) {
        return "";
    }
    final Intent intent = context.registerReceiver(
            null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
    if (intent != null) {
        final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
        if (wifiInfo != null) {
            final String ssid = wifiInfo.getSSID();
            if (ssid != null) {
                return ssid;
            }
        }
    }
    return "";
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:23,代碼來源:AndroidNetworkLibrary.java

示例2: getSSID

import android.net.wifi.WifiManager; //導入依賴的package包/類
public String getSSID() {
    WifiManager wifiManager = (WifiManager) getSystemService("wifi");
    if (wifiManager == null) {
        return null;
    }
    WifiInfo connectionInfo = wifiManager.getConnectionInfo();
    if (connectionInfo == null) {
        return null;
    }
    String ssid = connectionInfo.getSSID();
    if (ssid == null) {
        ssid = null;
    }
    return ssid;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:DeviceHelper.java

示例3: GetWifiDBM

import android.net.wifi.WifiManager; //導入依賴的package包/類
public int GetWifiDBM() {
    int dbm = 0;

    WifiManager wifiManager = (WifiManager) _context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null) {
        return -1;
    }

    if (wifiManager.isWifiEnabled()) {
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        if (wifiInfo != null) {
            dbm = wifiInfo.getRssi();
        }
    }

    return dbm;
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:18,代碼來源:NetworkController.java

示例4: handleButtonPress

import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void handleButtonPress(int index) {
  if (index == 0) {
    WifiParsedResult wifiResult = (WifiParsedResult) getResult();
    WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    if (wifiManager == null) {
      Log.w(TAG, "No WifiManager available from device");
      return;
    }
    final Activity activity = getActivity();
    activity.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(activity.getApplicationContext(), R.string.wifi_changing_network, Toast.LENGTH_SHORT).show();
      }
    });
    new WifiConfigManager(wifiManager).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, wifiResult);
    parent.restartPreviewAfterDelay(0L);
  }
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:21,代碼來源:WifiResultHandler.java

示例5: connectToKnownWifi

import android.net.wifi.WifiManager; //導入依賴的package包/類
public static void connectToKnownWifi(Context context, String ssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
    for (WifiConfiguration i : list) {
        if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
            wifiManager.disconnect();
            wifiManager.enableNetwork(i.networkId, true);
            wifiManager.reconnect();
        }
    }
}
 
開發者ID:hoanglm4,項目名稱:RxAndroidTBP,代碼行數:12,代碼來源:NetworkUtil.java

示例6: onReceive

import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    WifiManager wifiMgr = (WifiManager) context.getApplicationContext()
            .getSystemService(Service.WIFI_SERVICE);
    if (wifiMgr.isWifiEnabled()) {
        context.startService(new Intent(context, DeskDroidService.class));
    } else {
        context.stopService(new Intent(context, DeskDroidService.class));
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:11,代碼來源:WifiReceiver.java

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

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

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

示例10: onWifiEnabled

import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
public void onWifiEnabled()
{
    wifiLog("WIFI ENABLED...");
    unregisterReceiver(mContext, mWifiStateReceiver);
    if (mWifiStateListener != null)
        mWifiStateListener.isSuccess(true);

    if (mScanResultsListener != null || mPassword != null)
    {
        wifiLog("START SCANNING....");
        if (mWifiManager.startScan())
            registerReceiver(mContext, mWifiScanReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        else
        {
            if (mScanResultsListener != null)
                mScanResultsListener.onScanResults(new ArrayList<>());
            if (mConnectionWpsListener != null)
                mConnectionWpsListener.isSuccessful(false);
            mWifiConnectionCallback.errorConnect();
            wifiLog("COULDN'T SCAN ERROR");
        }
    }
}
 
開發者ID:ThanosFisherman,項目名稱:WifiUtils,代碼行數:25,代碼來源:WifiUtils.java

示例11: LockManager

import android.net.wifi.WifiManager; //導入依賴的package包/類
public LockManager(Context context) {
  PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full");
  partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial");
  proximityLock = new ProximityLock(pm);

  WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi");

  fullLock.setReferenceCounted(false);
  partialLock.setReferenceCounted(false);
  wifiLock.setReferenceCounted(false);

  accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() {
    @Override
    public void orientationChanged(int newOrientation) {
      orientation = newOrientation;
      Log.d(TAG, "Orentation Update: " + newOrientation);
      updateInCallLockState();
    }
  });

  wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:25,代碼來源:LockManager.java

示例12: getMacAddressByWifiInfo

import android.net.wifi.WifiManager; //導入依賴的package包/類
/**
 * <p>need permission {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
 */
@SuppressLint("HardwareIds")
private static String getMacAddressByWifiInfo(Context context) {
    try {
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wifi != null) {
            WifiInfo info = wifi.getConnectionInfo();
            if (info != null) return info.getMacAddress();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "02:00:00:00:00:00";
}
 
開發者ID:ChangsenLai,項目名稱:codedemos,代碼行數:17,代碼來源:DeviceUtil.java

示例13: writeToEntropyPool

import android.net.wifi.WifiManager; //導入依賴的package包/類
@Override
protected void writeToEntropyPool(DataOutputStream out) throws IOException {
	super.writeToEntropyPool(out);
	out.writeInt(android.os.Process.myPid());
	out.writeInt(android.os.Process.myTid());
	out.writeInt(android.os.Process.myUid());
	if (Build.FINGERPRINT != null) out.writeUTF(Build.FINGERPRINT);
	if (Build.SERIAL != null) out.writeUTF(Build.SERIAL);
	ContentResolver contentResolver = appContext.getContentResolver();
	String id = Settings.Secure.getString(contentResolver, ANDROID_ID);
	if (id != null) out.writeUTF(id);
	Parcel parcel = Parcel.obtain();
	WifiManager wm =
			(WifiManager) appContext.getSystemService(WIFI_SERVICE);
	List<WifiConfiguration> configs = wm.getConfiguredNetworks();
	if (configs != null) {
		for (WifiConfiguration config : configs)
			parcel.writeParcelable(config, 0);
	}
	BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
	if (bt != null) {
		for (BluetoothDevice device : bt.getBondedDevices())
			parcel.writeParcelable(device, 0);
	}
	out.write(parcel.marshall());
	parcel.recycle();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:28,代碼來源:AndroidSecureRandomProvider.java

示例14: checkWifiConnection

import android.net.wifi.WifiManager; //導入依賴的package包/類
private void checkWifiConnection(){
    try{
        if(isWifiConnected()){
            Toast.makeText(getApplicationContext(), "Wifi is connected", Toast.LENGTH_SHORT).show();
            WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            final String activeWifiName = wifiInfo.getSSID().replace("\"","");
            btnActiveWifi.setText(activeWifiName);
            //debug
            btnActiveWifi.setText(btnActiveWifi.getText()+"\n("+AutoLoginService.getState(getBaseContext())+")");

        }
        else{
            btnActiveWifi.setText("Wifi Not Connected !!");
            //debug
            btnActiveWifi.setText(btnActiveWifi.getText()+"\n("+AutoLoginService.getState(getBaseContext())+")");

        }}
    catch (Exception ex){
        txtView.setText(ex.getMessage());
        //Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG);
    }
}
 
開發者ID:debjeetmaj,項目名稱:AndroidWifiAutoLogin,代碼行數:24,代碼來源:MainActivity.java

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


注:本文中的android.net.wifi.WifiManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。