Skip to content

fix (when initailly there is no internet connection)#4

Open
milon27 wants to merge 1 commit intomitchtabian:masterfrom
milon27:master
Open

fix (when initailly there is no internet connection)#4
milon27 wants to merge 1 commit intomitchtabian:masterfrom
milon27:master

Conversation

@milon27
Copy link
Copy Markdown

@milon27 milon27 commented Jul 7, 2021

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)
    }

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.
@mitchtabian
Copy link
Copy Markdown
Owner

mitchtabian commented Jul 7, 2021

What device/version are you testing on? I cannot reproduce with API 30 pixel XL

@milon27
Copy link
Copy Markdown
Author

milon27 commented Jul 7, 2021

Pixel_4a_API_30

@mitchtabian
Copy link
Copy Markdown
Owner

I'm unable to reproduce with that exact device. I don't know what to tell you.

@milon27
Copy link
Copy Markdown
Author

milon27 commented Jul 7, 2021

If you don't have internet connection and launch the app first time do you have that no internet connection banner?

@mitchtabian
Copy link
Copy Markdown
Owner

mitchtabian commented Jul 7, 2021 via email

@milon27
Copy link
Copy Markdown
Author

milon27 commented Jul 7, 2021

Its confusing. I don't know why this is happening with some of us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants