Android disconnect wifi network

Android disconnects automatically from WiFi without internet below Android 10

Working on an android application in which I need to connect WiFi device programatically which does not have internet. Here is a code:

 private void connectToWiFi(final String ssid, String password) < if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) < WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); final ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkRequest.Builder request = new NetworkRequest.Builder(); request.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); request.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); // Internet not required ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() < @Override public void onAvailable(Network network) < String networkSSID = getNetworkSsid(); if (networkSSID.equals(ssid)) < connectivityManager.bindProcessToNetwork(network); >> @Override public void onUnavailable() < super.onUnavailable(); >@Override public void onLost(@NonNull Network network) < super.onLost(network); >>; connectivityManager.registerNetworkCallback(request.build(), networkCallback); WifiConfiguration config = new WifiConfiguration(); config.SSID = String.format("\"%s\"", ssid); int netId = -1; List apList = wifiManager.getConfiguredNetworks(); for (WifiConfiguration i : apList) < if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) < netId = i.networkId; >> // Add network in Saves network list if it is not available in list if (netId == -1) < if (TextUtils.isEmpty(password)) < Log.d(TAG, "====== Connect to open network"); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); >else < Log.d(TAG, "====== Connect to secure network"); config.preSharedKey = String.format("\"%s\"", password); >netId = wifiManager.addNetwork(config); > Log.d(TAG, "Connect to Network : " + netId); wifiManager.enableNetwork(netId, true); > else < // For Android 10 and above // WifiNetworkSpecifier code >> 

Above code works fine for the networks that offer internet connection. But it fails in most of the cases for the networks without internet connection. When attempting to connect to a WiFi configuration which does not have internet access, we need to bind our app’s process to that network, or configure our HTTP client to use that network’s socket factory, otherwise the system will disconnect from this WiFi network. As per this guideline , bindProcessToNetwork is already applied. But system is disconnecting from the network regardless of the use of bindToProcess() / routing traffic over the socket factory. It is not allowing to remain connected with the WiFi which don’t have internet. It is really surprising, Android has never thought for IoT device use cases before restricting to network connection. When attempting to connect to a WiFi network added by my app or system settings app or any other app, the system logs reveal: UID xxxxx does not have permission to update configuration Same error is not occurring when app tries to connect device which has internet even if that network is added by some other app. So the app is allowed to connect to the previous configuration, albeit with ‘insufficient permissions’, and traffic is momentarily routed over this network. But after a few seconds, the network is disconnected, and the system attempts to re-associate with some other internet-enabled network. Testing on Moto G5 Plus, Android 8.1.0, but I believe this is a platform bug, not device specific. And mostly this bug is introduced from Android 7 or something because it was working previously. I have also reported issue here. Also provided sample app in this issue. Is there any solution available for this issue ? Is there any option of paid support from Android ? Thanks in advance.

Читайте также:  Трафик wi fi iphone

Источник

13 Fixes For Android WiFi Keeps Disconnecting and Reconnecting Issue

Do you often get annoyed when you try to watch a video, but it keeps freezing because of an unstable network? Are you an android user having trouble connecting to the wifi network at home or work?

If these woes sound familiar to you, you’ve come to the right place.

Android wifi keeps disconnecting and reconnecting issue

In our WiFi troubleshooting tutorial for android, we’ve handpicked the top 13 ways that will assist you in resolving the Android WiFi Keeps Disconnecting and Reconnecting issue and help you get back online.

Why does my Android keep dis­con­necting from WiFi so often?

Suppose your android device keeps disconnecting from a WiFi router. In that case, it often indicates that something is interfering with your android phone’s ability to connect to the modem or WiFi network properly.

It’s usually an issue with your device’s wireless drivers but that may not always be the case. When you connect to your hotspot with a newer Android phone or tablet, it will try to test your Internet connection. It may end up mistakenly detecting a bad internet connection when it’s working perfectly well.

However, these WiFi network issues are more often caused by your internet connectivity issues than your Android device.

Solutions to Fix Android WiFi Keeps Disconnecting and Reconnecting Issue

  1. Restart Your Phone
  2. Forget the WiFi Networks
  3. Reset the Network Settings
  4. Restart Your WiFi Router
  5. Disable MAC Address Filtering
  6. Upgrade Your WiFi Router’s Firmware
  7. Disable Adaptive Wi-Fi/Wi-Fi+ on Android
  8. Check on the Conflicting Applications
  9. Boot Into Safe Mode
  10. Update Your Phone
  11. Turn Airplane Mode On/Off
  12. Change Your Router’s Range
  13. Factory Reset Your Phone

Let’s dive into step-by-step instructions for each one of them.

Android WiFi Keeps Disconnecting and Reconnecting Issue

1. Restart Your Phone

This may sound like generic advice, but sometimes that’s all it takes to fix a bad network connection.

When you close an app on your phone, it’s not close – it stays in your phone memory, slowly jamming up your device.

A certain chunk of RAM in your phone keeps storing new information in the background related to all the different things you opened up while switching back and forth between multiple apps.

It then makes it available to you instantly if you want to reopen the same contents, with the last unsaved actions it remembered.

So, restart your phone, and all your previously opened apps are cleared out, making way for new information to be logged in. In a nutshell, restarting your phone helps you begin with a clean slate.

So, you should consider restarting your Android phone at least once a week to help save memory and avoid random crashes. It may take a few minutes, but the outcome is well worth the time and effort.

  1. Unlock your phone.
  2. Hold the Power button down for a few seconds.
  3. Now, select the Restart option.

2. Forget the WiFi Networks

Check whether your phone can connect to other available networks without any issues. If it does, the problem may lie with your network.

Читайте также:  Автоматическое переключение между wi fi сетями

1- Go to Connections in the Settings app on your Android phone.

Connections section in the Android settings

2- Under Connections, select the ‘Wi-Fi’ option at the top.

Connections settings page

3- If connected to a WiFi network, tap on the Settings icon next to your WiFi name.

Wi-Fi settings page

4- At the bottom right of the screen, click on Forget from the current WiFi details page.

Network connection details

This will erase the WiFi network from your device’s memory. To reconnect, enter your WiFi credentials– Network name and Password and check if the problem persists.

3. Reset the Network Settings

Sometimes, your phone can pose issues while detecting the best network around from among your previously saved ones. If the problem exists with the other networks as well, follow the below steps to delete all the existing network connections:

Settings page with the General management settings

  1. From General, scroll down and tap Reset at the bottom of the screen.

Reset button in the General management settings

Reset options in the reset page

  1. Now, you will get an option to select all network settings include, Wi-Fi, Mobile data and Bluetooth. Tap on Reset settings. Finally, reboot your phone.

Reset network settings page

4. Restart Your WiFi Router

As with phones, restarting the router will reset its hardware and can fix a host of random network connectivity issues.

The instructions for a reboot can be found in your router provider’s manual or website.

These are the usual steps to follow:

  1. Unplug router and modem from the power outlet.
  2. Wait for 10 to 15 seconds.
  3. Plug the modem back in and allow 1-2 minutes before turning back on
  4. Plug in the router and allow at least 2 minutes for a proper boot up. Now, check if the problem is resolved.

5. Disable MAC Address Filtering feature

Media Access Control (MAC) address is a unique identifier assigned to a system by its manufacturer and remains unchanged.

Most routers develop a secure filtering system based on unique MAC addresses. Ensure your device is not filtered under a blocklist and is permitted to connect.

  1. Open your web browser, type your router’s default configuration code (e.g. 192.168.1.1) into address bar and hit Enter.

TP-Link network and router interface

  1. Type in the username and password and log in to your admin dashboard.
  2. Select Security → MAC Filtering from the left side of the page.
  3. You can see a list of currently filtered MAC addresses. Check the box on ‘Permit MAC Addresses listed belowand deny the rest’.

MAC addresses in the Wi-Fi interface

Now, click on Add New and type in your MAC address. Set the Status as ‘Enabled’.

Alternatively, click Modify next to your MAC address and change the permissions.

6. Upgrade Your WiFi Router’s Firmware

You need to create a backup before upgrading.

  1. From your router dashboard, go to System Tools → Backup & Restore. Select Backup to save your current configuration.

Backup & Restore option

  1. Now, go to System ToolsFirmware Upgrade, select Browse to get the extracted firmware. Then, click Upgrade. It will prompt an automatic reboot.
  2. Go to System ToolsFactoryDefaultRestore for the update to complete.

Now, go to System Tools → Firmware Upgrade, select Browse to get the extracted firmware.

7. Disable Adaptive Wi-Fi/Wi-Fi+ on Android

Wi-Fi + or adaptive Wi-Fi is a built-in feature in all the new Android smartphones these days, it lets you automatically switch between the mobile network and WiFi depending on the quality of the signal strength.

While it has its benefits, it can cause your network to repeatedly disconnect or drop arbitrarily, which can cause an issue with your Android phone’s connectivity.

Читайте также:  Телефон на телевизор самсунг wifi

Follow the below steps to disable this feature:

  1. From Settings, head over to Connections.
  2. Select Wi-Fi, then click on the three dots on the top right of the screen.

Advanced Wi-Fi settings option

  1. Click on Advanced. Under the Intelligent Wi-Fi, turn the toggle off on ‘Switch to mobile data’.

Advanced WiFi settings page

  1. Alternatively, in phones where Wi-Fi+ feature is available, you can click on SettingsWi-Fi → Turn off the Wi-Fi + under Wi-Fi menu.

Wi-FI+ Settings page

8. Check on the conflicting applications

Certain applications can affect your phone functionality and cause network issues due to permission or network conflicts like VPN, Antivirus, WiFi booster apps, etc.

You can temporarily try to disable these apps and recheck your network. Or, you can manually turn off certain network permissions that may have been triggering the problem.

9. Boot Into Safe Mode

A third-party application could also trigger your WiFi issue without your awareness. Safe Mode on Android disables all third-party programs and forces your smartphone to boot up with the default system apps. This will also verify whether any of these third-party apps are the main culprits behind the issue.

  1. Unlock your phone, press and hold down the Power button.
  2. Click on Power in the pop-up menu
  3. Press down Power off until you see Reboot to Safe Mode.
  4. Click OK.

10. Update Your Phone

Your network issues could also be showing up due to your phone’s software acting up due to certain bugs. It’s best to keep your Android device up-to-date with the latest software update.

Software update menu in the Android settings

Download and install option in the Software update page

  1. A pop-up indicates a new software update is available to install. Click on Install now to start the installation.

Update ready to install page with the Install Now and Installation Scheduling option

11. Turn Airplane Mode On/Off

Yet another way is to try and toggle your airplane mode on and off simultaneously. Airplane mode blocks your smartphone from connecting to any available network – Bluetooth, WiFi or mobile networks. It will reset your network preferences and makes your device start afresh.

12. Change Your Router’s Range

If your WiFi keeps disconnecting on Android, you can try and modify the AP(Access Point) band on your router.

You will need to head over to your router’s configuration page.

While a 5GHz frequency provides better network speeds, it also has a shorter range than the 2.4GHz band, which provides a better coverage area.

So it would help if you tried keeping your router at 2.4GHz.

  1. Select Connections from Settings.
  2. Under Connections, click on Mobile Hotspot and Tethering.

Hotspot and Tethering option in the Connection settings

Mobile Hotspot and Bluetooth tethering option

  1. Click Configure under Hotspot settings. Click on Band, then choose 2.4 GHz from the dropdown menu.

Setting a new hotspot option

13. Factory Reset Your Phone

If all the steps mentioned above fail to fix the android wifi keeps disconnecting and reconnecting, it could be an operating system issue and your only option might be to perform a factory rest on your phone. Don’t forget to backup all your data before starting a factory reset.

  1. Go to SettingsAbout Phone.
  2. Under Phone details, you’ll find the Reset option somewhere towards the end of the screen.

Reset option in the Phone details

Reset Network option page

Abdul Rahim has been working in Information Technology for over two decades. Learn how Abdul got his start as a Tech Blogger , and why he decided to start this Software blog. If you want to send Abdul a quick message, then visit his contact page here.

Источник

Оцените статью
Adblock
detector