Reputation: 2403
I'm trying to use NetworkRequest api from Android Q. It is showing the requested network in dialog. But when home button is pressed on device it automatically dismisses the request dialog, as when app is pushed to background and foreground the dialog is no more there.
But, if I lock and unlock the device the device the dialog stays as it is. Which is strange behaviour, as in both cases Activity will be paused and resumed, but the behaviour is different for request dialog.
Can someone help here in understanding the behaviour wether this is expected or some bug due to some configuration error while requesting network. Below is the code for NetworkRequest.
val specifier = WifiNetworkSpecifier.Builder()
.setSsidPattern(PatternMatcher(DEVICE_SSID, PatternMatcher.PATTERN_PREFIX))
.build()
val request = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.setNetworkSpecifier(specifier)
.build()
val connectivityManager = appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
connectivityManager.requestNetwork(request, networkCallback)
Upvotes: 0
Views: 580
Reputation: 742
Not sure if it's too late for this answer, but as the documentation for ConnectivityManager.requestNetwork()
suggests here, "the request will live until released via unregisterNetworkCallback(..)
or the calling application exits..."
This sounds mostly congruent with your experience, since ending your app's running process dismisses the Dialog automatically while simply 'pausing' it doesn't.
Upvotes: 1