Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

milon27
Copy link

@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
Owner

mitchtabian commented Jul 7, 2021

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

@milon27
Copy link
Author

milon27 commented Jul 7, 2021

Pixel_4a_API_30

@mitchtabian
Copy link
Owner

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

@milon27
Copy link
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
Owner

mitchtabian commented Jul 7, 2021 via email

@milon27
Copy link
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