当前位置: 首页>>代码示例>>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;未经允许,请勿转载。