food2fork-compose
food2fork-compose copied to clipboard
fix (when initailly there is no internet connection)
when you have an internet connection and you launch the app. it's showing connected with the internet. but when you turn off all networks and lanch the app again it's showing noting. the network callback did not trigger at all until you again turn on the wifi/internet.
fix this issue.
override fun onActive() {
networkCallback = createNetworkCallback()
val networkRequest = NetworkRequest.Builder()
.addCapability(NET_CAPABILITY_INTERNET)
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.build()
+ val ckInitialNet = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ cm.getNetworkCapabilities(cm.activeNetwork)
+ ?.hasCapability(NET_CAPABILITY_INTERNET)==true
+ } else {
+ val net=cm.allNetworks.find {
+ cm.getNetworkCapabilities(it)?.hasCapability(NET_CAPABILITY_INTERNET)==true
+ }
+ cm.getNetworkCapabilities(net)
+ ?.hasCapability(NET_CAPABILITY_INTERNET)==true
+ }
+ if(!ckInitialNet){
+ //initially there is no internet connection.
+ postValue(false)
+ }
cm.registerNetworkCallback(networkRequest, networkCallback)
}
What device/version are you testing on? I cannot reproduce with API 30 pixel XL
Pixel_4a_API_30
I'm unable to reproduce with that exact device. I don't know what to tell you.
If you don't have internet connection and launch the app first time do you have that no internet connection banner?
Yes
On Wed., Jul. 7, 2021, 2:56 p.m. Md Jahidul Islam, @.***> wrote:
If you don't have internet connection and launch the app first time do you have that no internet connection banner?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mitchtabian/food2fork-compose/pull/4#issuecomment-875960969, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFDMUDUD7XRLJC75RN5TFDTWTEQ5ANCNFSM477NW3EQ .
Its confusing. I don't know why this is happening with some of us.