Questions tagged [android-connectivitymanager]
159 questions
179
votes
28 answers
ConnectivityManager getNetworkInfo(int) deprecated
Using compileSdkVersion 23, however trying to support as far back as 9.
getNetworkInfo(int) was deprecated in 23. The suggestion was to use getAllNetworks() and getNetworkInfo(Network) instead. However both of these require minimum of API 21.
Is…

kyleED
- 2,327
- 2
- 18
- 23
91
votes
17 answers
activeNetworkInfo.type is deprecated in API level 28
I want to use the Connectivity manager which provide the method activeNetworkInfo.type for checking the type of network in Android. This method was deprecated in API level 28. so what is the solution to check network type in API 28. my code is…

Pitty
- 1,907
- 5
- 16
- 34
32
votes
7 answers
Difference between registerDefaultNetworkCallback and registerNetworkCallback
I came across registerDefaultNetworkCallback and registerNetworkCallback while updating my Android app for API 28.
Having reviewed the documentation, I cannot find the difference between registering a network callback and registering a default…

CybeX
- 2,060
- 3
- 48
- 115
26
votes
4 answers
How to handle network change between wifi and mobile data?
I am building a VoIP app.During a VoIP call when user switches between WiFi to mobile data i have a problem handling the scenario.
In my call screen activity I have registered for receiver which helps me get notified about the network change…

Jeeva
- 1,791
- 2
- 23
- 42
25
votes
1 answer
Getting Security exception while trying to fetch networkcapabilities on android 11
I am getting SecurityException followed by RemoteException while trying to access below code. API
val networkCapabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
Exception getting
Fatal Exception:…

Sudhansu
- 780
- 1
- 9
- 28
23
votes
5 answers
Android Q, programmatically connect to different WiFi AP for internet
As in Android Q, several WiFi APIs are restricted. I am trying to use alternate APIs to connect to different Wifi AP for internet.
Below is my code :
WifiNetworkSpecifier.Builder builder = new WifiNetworkSpecifier.Builder();
…

Vinodh
- 1,069
- 2
- 10
- 22
17
votes
3 answers
Android 10 / API 29 : how to connect the phone to a configured network?
I am working on an application in which one the user has to follow these steps :
connect the phone to wifi ;
connect the phone to a dedicated hotspot from a connected object.
When the user is connected to the dedicated hotspot of the connected…

rolandl
- 1,769
- 1
- 25
- 48
11
votes
0 answers
Android Q always reusing the first entered credentials to connect to the WiFi network
I am trying to connect to WiFi using the WifiNetworkSpecifier on Android Q. The problem which I run into is Android always using the last valid credentials to connect to the AP, even after I manually provide the new, updated credentials to the…

Luja93
- 451
- 3
- 8
11
votes
3 answers
How to get WIFI SSID in Android 9.0(PIE)?
How to get WIFI SSID in Android 9.0(PIE)? My code is working fine till android version 8.1.0 but it is not working on Android 9.0
ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
…

Abhinav Tiwari
- 131
- 1
- 1
- 5
9
votes
1 answer
Multiple random NetworkCallbacks (onAvailable) with same networkId from the ConnectivityManager
I don't understand why onAvailable is called multiple times at random moments, the documentation states that it can be called more if the network changes, but the properties of the network object parameter in onAvailable is always the same. I even…

DennisVA
- 2,068
- 1
- 25
- 35
9
votes
3 answers
ConnectivityManager.NetworkCallback() -> onAvailable(Network network) method is not triggered when device connects to a internal wifi network
I am trying to send telementary data to App Center on out internal wifi network but it is not sending on this network but it does on any external network. When debugging found that Method onAvailable() is not called when device is connected to…

S Gupta
- 139
- 1
- 3
- 11
9
votes
0 answers
ConnectivityManager.requestNetwork() not working as expected
I'm trying to temporarily force the device to use mobile data. I'm using ConnectivityManager.requestNetwork(),
NetworkRequest.Builder request = new NetworkRequest.Builder();
…

Jeffrey Blattman
- 22,176
- 9
- 79
- 134
8
votes
1 answer
Unable to get callback when internet is off and then app starts inside NetworkCallback
As getActiveNetworkInfo is deprecated now in Android according to official document, I am using below implementation to get callback about Internet connectivity.
private val connectivityManager: ConnectivityManager by lazy {
…

Jigar
- 421
- 2
- 11
7
votes
4 answers
Android Q Wifi connection via WifiNetworkSpecifier lose connection immediately after connection established
I'm currently trying to connect to a wifi network. I used the below code.
WifiNetworkSpecifier specifier = new WifiNetworkSpecifier.Builder()
.setSsid(ssid)
.setBssid(MacAddress.fromString(bssid))
…

Jayanth
- 5,954
- 3
- 21
- 38
7
votes
4 answers
Android ConnectivityManager onAvailable sometime not returned
We use the Android ConnectivityManager to listen for internet connection changes inside our app as follows.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
...
…

Linh
- 57,942
- 23
- 262
- 279