On Android Oreo or lower, WifiManager#getConfiguredNetworks() method was available to list saved network.
I tested this out in Android 10 emulator and it returns a blank list (as mentioned in the docs). Does anyone know whats the alternate?
Official docs
This method was deprecated in API level 29. a) See
WifiNetworkSpecifier.Builder#build() for new mechanism to trigger
connection to a Wi-Fi network. b) See
addNetworkSuggestions(java.util.List),
removeNetworkSuggestions(java.util.List) for new API to add Wi-Fi
networks for consideration when auto-connecting to wifi. Compatibility
Note: For applications targeting Build.VERSION_CODES.Q or above, this
API will return an empty list, except for:
Related
https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()
public boolean disable ()
This method was deprecated in API level 33.
Starting with Build.VERSION_CODES.TIRAMISU, applications are not allowed to enable/disable Bluetooth. Compatibility Note: For applications targeting Build.VERSION_CODES.TIRAMISU or above, this API will always fail and return false. If apps are targeting an older SDK (Build.VERSION_CODES.S or below), they can continue to use this API.
How to implement properly disabling bluetooth?
I have no problem with enable bluetooth, I do like this (following https://developer.android.com/guide/topics/connectivity/bluetooth/setup):
if (bluetoothAdapter?.isEnabled == false) {
val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
}
I was searching for solution, but in Android documentation they did not add proper implementation for disabling BT in Android API 33.
There is a simple reason why a normal application cannot simply turn off the Bluetooth sub-system in Android.
Nowadays, the Bluetooth sub-system is used by a large number of applications running simultaneously. One example is the Exposure Notifications Framework introduced for COVID 19 which is even part of the operating system. So if individual applications could simply switch off this sub-system, a large number of other applications would be negatively affected.
If you still feel that it is imperative for your application that Bluetooth be turned off, then ask the user to do so via the System menu.
I have a mobile application that allows users to enable/disable WiFi on click of a button.
However I noticed today that my app is no longer able to change the WiFi status. It was working since before few weeks. I tried to debug it but the following method always returns false.
boolean result = wifiManager.setWifiEnabled(true);
I am testing it on Samsung Galaxy Note 9 and Android 10.
This API is no longer supported when targeting Android 10 or higher.
Starting with Build.VERSION_CODES#Q, applications are not allowed to enable/disable Wi-Fi. Compatibility Note: For applications targeting Build.VERSION_CODES.Q or above, this API will always fail and return false. If apps are targeting an older SDK (Build.VERSION_CODES.P or below), they can continue to use this API.
Instead, you should use the Settings.Panel API to present a system UI allowing users to enable or disable Wi-Fi.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startActivity(Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY))
}
For a UiTest class setup, I need to begin with no remembered Wifi Networks.
To do this I use a combination of the WifiManager.getConfiguredNetworks() and WifiManager.removeNetwork(), both of which are now restricted and deprecated for Android Q.
Now, since I am running the tests in privileged mode (super user), the getConfiguredNetworks() method actually returns a full list of the networks, and the removeNetwork() removes networks I pass by returned WifiConfiguration's Ids, even though I run this code on an Android Q device.
TLDR:
My issue is more about these two methods being deprecated without being properly replaced, not that they now are worthless to use. At least not to my knowing, which is why I am asking; are there any way I, with my testapplication run as Super-user, can:
Retrieve all Wifi Configurations
Delete them one by one
In the documentation, one can read:
getConfiguredNetworks()
This method was deprecated in API level 29. a) See WifiNetworkSpecifier.Builder#build() for new mechanism to trigger connection to a Wi-Fi network. b) See addNetworkSuggestions(java.util.List), removeNetworkSuggestions(java.util.List) for new API to add Wi-Fi networks for consideration when auto-connecting to wifi. Compatibility Note: For applications targeting Build.VERSION_CODES.Q or above, this API will return an empty list.
The solutions they've linked seem to be for the action of connecting to wifi networks, but that isn't what I am looking for.
PS, I would be at least as happy by executing adb shell commands (in superuser-mode if needed), to do the same thing. Already tried using wpa_cli list_networks to at least list all networks, but doesn't seem to be available.
Also have tried to remove data/misc/wifi/wpa_supplicant and data/misc_ce/0/wifi/WifiConfigStore.xml, to no avail.
I cant get serial on android 10 device.
I know about everything(permission, runtime permissions, I get serial only after the permission is granted) from here
android Build.GetSerial() throwing exception
My code works on all android versions, except 10
Do you have any ideas?
If you follow the official documentation here: https://developer.android.com/reference/android/os/Build.html#getSerial(), more info on Android 10 changes here
You will notice that starting from Android 10 this method is returning Build.UNKNOWN. You can't use it to uniquely identify a single device anymore
You need to switch to the "less" persistent version called Settings.Secure.ANDROID_ID
The only ways to bypass this restriction are:
Create a system app to be able to get the READ_PRIVILEGED_PHONE_STATE system permission (a normal app can't get this).
Be registered as a carrier (which requires you to have built the Android ROM)
Have a custom "work profile" to set your own policies in the device.
As you can imagine, all those options are not meant to be used by standard android app developers
I have implemented the system to connect to wifi networks from my app programmatically, now I want to forget configured WIFI networks programmatically from the application.
I have implemented this into my application already and its been working fine on the Android 5.0 and lower devices (Less then API 22).
For Android 6.0 and the higher device it is not working (Higher and equal then API 23).
Please refer the following code:
val wifiManager = this#SelectWifiSettingsActivity.baseContext!!.getSystemService(android.content.Context.WIFI_SERVICE) as WifiManager
val list = wifiManager.configuredNetworks
for (i in list) {
wifiManager.disableNetwork(i.networkId)
wifiManager.saveConfiguration()
}
I have also referred the following link:
https://stackoverflow.com/a/33075445/9360112
As there are some changes in WIFI configurations in Android 6.0.
Please, help me if anyone has solution for this on Android 6.0 onwards.
First thing is you don't need to use saveConfiguration().
This method was deprecated in API level 26.
There is no need to call this method - addNetwork(WifiConfiguration), updateNetwork(WifiConfiguration) and removeNetwork(int) already persist the configurations automatically.
Secondly, what you're looking for is removeNetwork().
Your code will look like:
val wifiManager = this#SelectWifiSettingsActivity.baseContext!!.getSystemService(android.content.Context.WIFI_SERVICE) as WifiManager
val list = wifiManager.configuredNetworks
for (i in list) {
wifiManager.removeNetwork(i.networkId)
}
Being said that... There are some changes in the Android M APIs for WifiManager.
Your apps can now change the state of WifiConfiguration objects only
if you created these objects. You are not permitted to modify or
delete WifiConfiguration objects created by the user or by other apps.
See Network Changes in Android M