Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to programmatically enable wifi on Android 10 devices?

Since setWifiEnabled is deprecated on Android 10, how does one programatically enable wifi on Android 10 devices?

Is it not possible to programmatically enable wifi at all on Android 10+ (SDK 29) ?

like image 255
AdeleGoldberg Avatar asked Sep 24 '19 08:09

AdeleGoldberg


People also ask

How do you check if WiFi is on or off in android programmatically?

Checking the state of WiFi can be done by obtaining an instance to the WiFi system service as below: WifiManager wifi = (WifiManager)getSystemService(Context. WIFI_SERVICE); from this, the method isWifiEnabled() can be used to determine if WiFi is enabled.

What is WiFi manager in Android?

WiFi Manager is a tool to manage WiFi connections, thanks to which you will not only have the ability to find and connect to networks in your environment, but it also will improve the quality of those connections.

How do I use WiFi manager on Android?

Android Enable or Disable Wi-Fi Following is the code snippet to enable a Wi-Fi in android application by using setWifiEnabled() method. WifiManager wmgr = (WifiManager)Context. getSystemService(Context. WIFI_SERVICE);


2 Answers

No, This is not possible to enable or disable Wi-Fi programmatically from Android-10 API level 29 [Until google provides an alternative solution].

For applications targeting Build.VERSION_CODES.Q or above, this API will always return false and will have no effect.

If apps are targeting an older SDK ( Build.VERSION_CODES.P or below), they can continue to use this API.

There is an issue 128554616 which already has been created in google issuetracker forum. You can see there for any updated info.

like image 128
Jakir Hossain Avatar answered Sep 21 '22 15:09

Jakir Hossain


Now in android 10 you can do like this

Intent panelIntent = new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
startActivityForResult(panelIntent);

ACTION_INTERNET_CONNECTIVITY Shows settings related to internet connectivity, such as Airplane mode, Wi-Fi, and Mobile Data.

ACTION_WIFI Shows Wi-Fi settings, but not the other connectivity settings. This is useful for apps that need a Wi-Fi connection to perform large uploads or downloads.

ACTION_NFC Shows all settings related to near-field communication (NFC).

ACTION_VOLUME Shows volume settings for all audio streams.

like image 26
Ali Imran Avatar answered Sep 21 '22 15:09

Ali Imran