Java 类android.net.wifi.WifiManager 实例源码

项目:chromium-net-for-android    文件:AndroidNetworkLibrary.java   
/**
 * 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 "";
}
项目:RxAndroidTBP    文件:NetworkUtil.java   
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();
        }
    }
}
项目:featurea    文件:WifiUtil.java   
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;
}
项目:boohee_v5.6    文件:LocationInfo.java   
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;
}
项目:letv    文件:NetworkHelper.java   
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;
}
项目:AndroidBasicLibs    文件:NetUtils.java   
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;
}
项目:WifiUtils    文件:WifiUtils.java   
@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");
        }
    }
}
项目:Cable-Android    文件:LockManager.java   
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);
}
项目:codedemos    文件:DeviceUtil.java   
/**
 * <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";
}
项目:Nird2    文件:AndroidSecureRandomProvider.java   
@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();
}
项目:AndroidWifiAutoLogin    文件:MainActivity.java   
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);
    }
}
项目:PrivacyStreams    文件:WifiApListProvider.java   
@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();
}
项目:YiZhi    文件:NetworkConnectionUtils.java   
/**
 * 给温控器成功发送联网命令后,连接温控器连接的wifi节点
 *
 * @param context  上下文对象
 * @param ssid     ssid
 * @param password 密码
 */
public static void connectWifiSSID(Context context, WifiManager manager, String ssid, String
        password) {
    e("reSetNetwork----------连接设备连入的路由---" + ssid);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        e("当前手机系统>=Android6.0,采取兼容模式");
        new WifiAutoConnectManager(manager).connect(ssid, password, WifiAutoConnectManager
                .getCipherType(context, ssid));
    } else {
        int networkId = manager.addNetwork(getWifiConfiguration(manager, ssid, password));
        if (networkId != -1) {
            manager.enableNetwork(networkId, true);
        }
    }
}
项目:LucaHome-AndroidApplication    文件:NetworkController.java   
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;
}
项目:boohee_v5.6    文件:DeviceHelper.java   
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;
}
项目:Android-UtilCode    文件:NetworkUtils.java   
/**
 * 打开或关闭wifi
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>}</p>
 *
 * @param enabled {@code true}: 打开<br>{@code false}: 关闭
 */
public static void setWifiEnabled(boolean enabled) {
    @SuppressLint("WifiManagerLeak")
    WifiManager wifiManager = (WifiManager) Utils.getContext().getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
        if (!wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(true);
        }
    } else {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
    }
}
项目:TaipeiTechRefined    文件:WifiUtility.java   
public static String getCurrentSSID(Context context) throws Exception {
    try {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    } catch (Exception e) {
        throw new Exception("目前WIFI連線名稱讀取時發生錯誤");
    }

}
项目:OCast-Java    文件:WifiMonitor.java   
@Override
public void onReceive(Context context, Intent intent) {
    if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
        NetworkInfo networkInfo =
                intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if(networkInfo.isConnected()) {
            if(!mIsConnected) {
                Log.d(TAG, "Wifi is connected: " + String.valueOf(networkInfo));
                mListener.onConnectionStateChanged(true);
                mIsConnected = true;
            }
        } else {
            if(mIsConnected) {
                Log.d(TAG, "Wifi is disconnected: " + String.valueOf(networkInfo));
                mIsConnected = false;
                mListener.onConnectionStateChanged(false);
            }
        }
    }
}
项目:ModuleFrame    文件:DeviceUtil.java   
/**
 * 获取设备MAC地址
 *
 * @return MAC地址
 */
@SuppressLint("HardwareIds")
@RequiresPermission(Manifest.permission.ACCESS_WIFI_STATE)
private static String getMacAddressByWifiInfo(Context context) {
    try {
        @SuppressLint("WifiManagerLeak")
        WifiManager wifi = (WifiManager) context.getApplicationContext().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";
}
项目:LucaHome-AndroidApplication    文件:NetworkController.java   
public String GetWifiSsid() {
    if (!IsWifiConnected()) {
        return "";
    }

    ConnectivityManager connectivityManager = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
        return "";
    }

    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    if (activeNetwork != null) {
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
            WifiManager wifiManager = (WifiManager) _context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            if (wifiManager == null) {
                return "";
            }

            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            return wifiInfo.getSSID();
        } else {
            Logger.getInstance().Warning(TAG, "Active network is not wifi: " + String.valueOf(activeNetwork.getType()));
        }
    }

    return "";
}
项目:weex-3d-map    文件:WifiResultHandler.java   
@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);
  }
}
项目:Thesis_Farmers_Helper    文件:Network_Wifi_Class.java   
public Network_Wifi_Class(Context context,Activity activity){
    this.mApplicationContext = context;
    this.mApplicationActivity = activity;
    simplyProgressBar = new SimplyProgressBar();
    mWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
项目:YiZhi    文件:WifiAutoConnectManager.java   
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;
}
项目:xlight_android_native    文件:WifiScanResultLoader.java   
public WifiScanResultLoader(Context context) {
    super(context);
    Context appCtx = context.getApplicationContext();
    receiver = SimpleReceiver.newReceiver(
            appCtx, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION),
            (ctx, intent) -> {
                log.d("Received WifiManager.SCAN_RESULTS_AVAILABLE_ACTION broadcast");
                forceLoad();
            });
    wifiFacade = WifiFacade.get(context);
}
项目:letv    文件:c.java   
public static String a() {
    try {
        Context context = Global.getContext();
        if (context == null) {
            return "";
        }
        WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
        if (wifiManager == null) {
            return "";
        }
        WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        if (connectionInfo == null) {
            return "";
        }
        return connectionInfo.getMacAddress();
    } catch (Throwable e) {
        f.b("MobileInfoUtil", "getLocalMacAddress>>>", e);
        return "";
    }
}
项目:Auto.js    文件:WifiTool.java   
public static String getWifiAddress(Context context) {
    WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
    if(wifiMgr == null){
        return null;
    }
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    return Formatter.formatIpAddress(ip);
}
项目:Java-9-Programming-Blueprints    文件:WifiReceiver.java   
@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));
    }
}
项目:RxAndroidTBP    文件:NetworkUtil.java   
public static String getConnectedSSID(Context context) {

        if (context == null)
            return null;
        String networkName = null;
        int networkState = getConnectionStatus(context);
        Log.i(TAG, "Network State:" + networkState);
        if (networkState == NetworkUtil.WIFI) { //no wifi connection and alert dialog allowed //i-why no wifi connection?
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            if (wifiManager != null) {
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                if (wifiInfo != null) {
                    networkName = wifiInfo.getSSID().replaceAll("\"", "");
                }
            }
        }
        if (networkName == null || networkName.equals("<unknown ssid>") || networkName.equals("0x") || networkName.equals("")) {
            networkName = null;
        }

        return networkName;
    }
项目:BadIntent    文件:BadIntentPreferencesActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //try to set this WiFi IP (in case there is no [valid] value set yet)
    WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    String wifiIP = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
    SharedPreferences sPrefs = getSharedPreferences(AppAnalyzer.PREFNAME, MODE_WORLD_READABLE);
    String target_ip = sPrefs.getString(BadIntentConstants.TARGET_IP, " ");
    if (target_ip.equals(" ") || target_ip.equals("0.0.0.0")) {
        sPrefs.edit()
                .putString(BadIntentConstants.TARGET_IP, wifiIP)
                .apply();
    }
    addPreferencesFromResource(R.xml.bad_intent_preferences);

}
项目:Quran    文件:QuranDownloadService.java   
@Override
public void onCreate() {
  super.onCreate();
  HandlerThread thread = new HandlerThread(TAG);
  thread.start();

  Context appContext = getApplicationContext();
  mNotifier = new QuranDownloadNotifier(this);
  mWifiLock = ((WifiManager) appContext.getSystemService(Context.WIFI_SERVICE))
      .createWifiLock(WifiManager.WIFI_MODE_FULL, "downloadLock");

  mServiceLooper = thread.getLooper();
  mServiceHandler = new ServiceHandler(mServiceLooper);
  mIsDownloadCanceled = false;
  mSuccessfulZippedDownloads = new HashMap<>();
  mRecentlyFailedDownloads = new HashMap<>();
  mQuranSettings = QuranSettings.getInstance(this);

  ((QuranApplication) getApplication()).getApplicationComponent().inject(this);
  mBroadcastManager = LocalBroadcastManager.getInstance(appContext);
}
项目:HeadlineNews    文件:DeviceUtils.java   
/**
 * 获取设备MAC地址
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p>
 *
 * @return MAC地址
 */
@SuppressLint("HardwareIds")
private static String getMacAddressByWifiInfo() {
    try {
        @SuppressLint("WifiManagerLeak")
        WifiManager wifi = (WifiManager) Utils.getContext().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";
}
项目:Misc    文件:WifiActivity.java   
/**
 * 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);
    }
}
项目:RxAndroidTBP    文件:MDnsHelper.java   
private InetAddress getDeviceIpAddress(WifiManager wifi) {
    InetAddress result = null;
    try {
        // default to Android localhost
        result = InetAddress.getByName("10.0.0.2");

        // figure out our wifi address, otherwise bail
        WifiInfo wifiinfo = wifi.getConnectionInfo();
        int intaddr = wifiinfo.getIpAddress();
        byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) };
        result = InetAddress.getByAddress(byteaddr);
    } catch (UnknownHostException e) {
        e.printStackTrace();
        Log.e(TAG, "getDeviceIpAddress Error: " + e.getMessage());
    }

    return result;
}
项目:NoInternetDialog    文件:NoInternetUtils.java   
static void turnOnWifi(Context context) {
    WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);

    if (wifiManager == null || isConnectedToWifi(context)) {
        context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
        return;
    }

    wifiManager.setWifiEnabled(true);
}
项目:GitHub    文件:NetworkUtils.java   
/**
 * 获取当前连接wifi的名称
 *
 * @return
 */
public static String getConnectWifiSsid(Context context) {
    if (isWifiConnected(context)) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getSSID();
    }
    return null;
}
项目:Hotspot-master-devp    文件:WifiUtil.java   
public  static String getWifiName(Context context) {
    if(context == null)
        return null;
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifiMgr.getConnectionInfo();
    String wifiId = info != null ? info.getSSID() : null;
    if(!TextUtils.isEmpty(wifiId)) {
        wifiId = wifiId.replace("\"","");
    }
    return wifiId;
}
项目:boohee_v5.6    文件:c.java   
private static String b(Context context) {
    WifiInfo connectionInfo = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo();
    if (connectionInfo != null) {
        return connectionInfo.getSSID();
    }
    return "-1";
}
项目:letv    文件:LetvUtil.java   
public static String getLocalIpAddress(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService("connectivity");
    NetworkInfo wifi = connMgr.getNetworkInfo(1);
    NetworkInfo mobile = connMgr.getNetworkInfo(0);
    if (wifi.isAvailable()) {
        WifiManager wifimanage = (WifiManager) context.getSystemService("wifi");
        wifimanage.isWifiEnabled();
        int i = wifimanage.getConnectionInfo().getIpAddress();
        return (i & 255) + "." + ((i >> 8) & 255) + "." + ((i >> 16) & 255) + "." + ((i >> 24) & 255);
    }
    if (mobile.isAvailable()) {
        try {
            Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                Enumeration<InetAddress> enumIpAddr = ((NetworkInterface) en.nextElement()).getInetAddresses();
                while (enumIpAddr.hasMoreElements()) {
                    InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        return inetAddress.getHostAddress().toString();
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
    return null;
}
项目:FindX    文件:digiPune.java   
void startWifi()
{

    WifiManager wifiManager = (WifiManager) this
            .getSystemService(Context.WIFI_SERVICE);
    if(!wifiManager.isWifiEnabled())
        wifiManager.setWifiEnabled(true);

}
项目:xlight_android_native    文件:WifiFacade.java   
public static WifiFacade get(Context ctx) {
    Context appCtx = ctx.getApplicationContext();
    return new WifiFacade(
            (WifiManager) appCtx.getSystemService(Context.WIFI_SERVICE),
            (ConnectivityManager) appCtx.getSystemService(Context.CONNECTIVITY_SERVICE)
    );
}