Java Code Examples for android.net.wifi.WifiManager#isWifiEnabled()
The following examples show how to use
android.net.wifi.WifiManager#isWifiEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WiFiUtils.java From FimiX8-RE with MIT License | 6 votes |
public static String getPhoneIp(Context application) { WifiManager wifiManager = (WifiManager) application.getSystemService("wifi"); if (wifiManager.isWifiEnabled()) { return intToIp(wifiManager.getConnectionInfo().getIpAddress()); } 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; }
Example 2
Source File: Utils.java From adb_wireless with Apache License 2.0 | 6 votes |
public static boolean checkWifiState(Context context) { try { WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); if (!mWifiManager.isWifiEnabled() || wifiInfo.getSSID() == null) { return false; } return true; } catch (Exception e) { return false; } }
Example 3
Source File: DownloadService.java From rcloneExplorer with MIT License | 6 votes |
private boolean checkWifiOnAndConnected() { WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if (wifiMgr == null) { return false; } if (wifiMgr.isWifiEnabled()) { // Wi-Fi adapter is ON WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); return wifiInfo.getNetworkId() != -1; } else { return false; // Wi-Fi adapter is OFF } }
Example 4
Source File: ScanService.java From find3-android-scanner with MIT License | 6 votes |
@Override public void onCreate() { // The service is being created Log.d(TAG, "creating new scan service"); queue = Volley.newRequestQueue(this); // setup wifi wifi = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if (wifi.isWifiEnabled() == false) { wifi.setWifiEnabled(true); } // register wifi intent filter IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); registerReceiver(mWifiScanReceiver, intentFilter); try { // setup bluetooth Log.d(TAG, "setting up bluetooth"); if (receiver == null) { receiver = new BluetoothBroadcastReceiver(); registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND)); } } catch (Exception e) { Log.e(TAG, e.toString()); } }
Example 5
Source File: LocAlarmService.java From ownmdm with GNU General Public License v2.0 | 6 votes |
/** * get wifi networks */ String getWifi() { final String redes = ""; try { String connectivity_context = Context.WIFI_SERVICE; final WifiManager wifi = (WifiManager) getSystemService(connectivity_context); if (wifi.isWifiEnabled()) { wifi.startScan(); } else { Util.wifiApagado = true; wifi.setWifiEnabled(true); wifi.startScan(); } } catch(Exception e) { Util.logDebug("Exception (getWifi): " + e.getMessage()); } return redes; }
Example 6
Source File: WifiBaseActivity.java From android-wifi-activity with Creative Commons Zero v1.0 Universal | 6 votes |
/** * Start connecting to specific wifi network */ protected void handleWIFI() { WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); if (!wifi.isWifiEnabled()) { showWifiDisabledDialog(); } else { if (!permisionLocationOn()) { setLocationPermission(); } else { if (checkLocationTurnOn()) { connectToSpecificNetwork(); } } } }
Example 7
Source File: Common.java From NonViewUtils with Apache License 2.0 | 6 votes |
/** * 打开或关闭WIFI * * @param mContext Context * @param action 打开使用on 关闭使用off */ public static void onWifi(Context mContext, String action) { WifiManager wm = ((WifiManager) mContext .getSystemService(Context.WIFI_SERVICE)); if (action.toLowerCase().equalsIgnoreCase("on")) { if (!wm.isWifiEnabled()) { wm.setWifiEnabled(true); } } if (action.toLowerCase().equalsIgnoreCase("off")) { if (wm.isWifiEnabled()) { wm.setWifiEnabled(false); } } }
Example 8
Source File: Util.java From ki4a with Apache License 2.0 | 6 votes |
protected static void prepareInterfaces(WifiManager wifiManager, TelephonyManager telephonyManager) { // If wifi is On, we need to turn it off first if(wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(false); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } if(ki4aService.preferences.getBoolean("cellular_switch",true) && ki4aService.preferences.getBoolean("airplane_switch",true)) { // If data connection is not connected, we'll try to bring it up if (telephonyManager.getDataState() != telephonyManager.DATA_CONNECTED && telephonyManager.getDataState() != telephonyManager.DATA_CONNECTING) Util.refreshMobileData(); } }
Example 9
Source File: NetworkUtils.java From pandroid with Apache License 2.0 | 5 votes |
/** * Disable wifi * * @param context * @return true if the operation succeeds (or if the existing state is the same as the requested state). */ @RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE) public static boolean disableWifi(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { return wifiManager.setWifiEnabled(false); } return true; }
Example 10
Source File: IpUtil.java From BaseProject with MIT License | 5 votes |
/** * 获取IP地址(网络为Wifi) */ @RequiresPermission(allOf = {Manifest.permission.CHANGE_WIFI_STATE, Manifest.permission.ACCESS_WIFI_STATE}) public static String getWifiIp(@NonNull Context context) { // 获取wifi服务 WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); // 判断wifi是否开启 if (null != wifiManager && !wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(true); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); return intToIp(ipAddress); } return null; }
Example 11
Source File: NetworkMonitor.java From android-utilset with Apache License 2.0 | 5 votes |
/** * Checks if WiFi is turned on<br> * Requires ACCESS_NETWORK_SATE, READ_PHONE_STATE permissions<br> * * @return true if WiFi is turned on; false otherwise */ public boolean isWifiEnabled() { WifiManager wm = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); if (wm == null) { return false; } return wm.isWifiEnabled(); }
Example 12
Source File: CallActivity.java From q-municate-android with Apache License 2.0 | 5 votes |
private void processCurrentWifiState(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(WIFI_SERVICE); if (wifiEnabled != wifi.isWifiEnabled()) { wifiEnabled = wifi.isWifiEnabled(); ToastUtils.longToast("Wifi " + (wifiEnabled ? "enabled" : "disabled")); } }
Example 13
Source File: LetvUtil.java From letv with Apache License 2.0 | 5 votes |
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; }
Example 14
Source File: DeviceStatusUtil.java From under-the-hood with Apache License 2.0 | 5 votes |
/** * Current Wifi hardware state. Needs correct permission to work. * * @param context * @return state */ //@RequiresPermission(Manifest.permission.ACCESS_WIFI_STATE) public static Status getWifiStatus(Context context) { WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifi == null) { return Status.UNSUPPORTED; } else if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) { return Status.NEEDS_PERMISSION; } else if (wifi.isWifiEnabled()) { return Status.ENABLED; } else { return Status.DISABLED; } }
Example 15
Source File: ConfigureWifiActivity.java From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean scanWifiNetworks(){ final boolean isAirplaneEnabled = Settings.System.getInt(getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) == 1; final WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE); if((isAirplaneEnabled && wifiManager.isWifiEnabled()) || wifiManager.isWifiEnabled()) { wifiReciever = new WifiScanReceiver(); registerReceiver(wifiReciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); showWifiProgressbar(); this.wifiManager.startScan(); return true; } else return false; }
Example 16
Source File: WifiReceiver.java From NetworkGhost with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN); String wifiStateText = "No State"; String action = intent.getAction(); if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { WifiManager manager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = intent .getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); NetworkInfo.State state = networkInfo.getState(); if (state == NetworkInfo.State.DISCONNECTED) { if (manager.isWifiEnabled()) { doUpdate(context); wifiStateText = "WIFI_STATE_DISCONNECTED"; } } } switch (wifiState) { case WifiManager.WIFI_STATE_DISABLING: wifiStateText = "WIFI_STATE_DISABLING"; break; case WifiManager.WIFI_STATE_DISABLED: wifiStateText = "WIFI_STATE_DISABLED"; break; case WifiManager.WIFI_STATE_ENABLING: wifiStateText = "WIFI_STATE_ENABLING"; break; case WifiManager.WIFI_STATE_ENABLED: wifiStateText = "WIFI_STATE_ENABLED"; if (state == 1) state--; else doUpdate(context); break; case WifiManager.WIFI_STATE_UNKNOWN: wifiStateText = "WIFI_STATE_UNKNOWN"; break; default: break; } System.out.println("WIFI_recv: " + wifiStateText); }
Example 17
Source File: MyUtils.java From SimplePomodoro-android with MIT License | 4 votes |
public static boolean isWifiEnabled(Context c){ WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); return wifi.isWifiEnabled(); }
Example 18
Source File: PhoneWifiHelper.java From arcusandroid with Apache License 2.0 | 4 votes |
public static boolean isWifiEnabled () { final WifiManager wifiManager = getWiFiManager(ArcusApplication.getArcusApplication()); return wifiManager.isWifiEnabled(); }
Example 19
Source File: NetworkUtils.java From BaseProject with Apache License 2.0 | 3 votes |
/** * 打开或关闭wifi * <p> * 需添加权限 * {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>} * </p> * * @param context * 上下文 * @param enabled * {@code true}: 打开<br> * {@code false}: 关闭 */ public static void setWifiEnabled(Context context, boolean enabled) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (enabled) { if (!wifiManager.isWifiEnabled()) { // wifiManager.setWifiEnabled(true); } } else { if (wifiManager.isWifiEnabled()) { // wifiManager.setWifiEnabled(false); } } }
Example 20
Source File: XNetworkUtils.java From XFrame with Apache License 2.0 | 2 votes |
/** * 判断wifi是否打开 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>}</p> * * @return {@code true}: 是<br>{@code false}: 否 */ public static boolean getWifiEnabled() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wifiManager.isWifiEnabled(); }