food2fork-compose icon indicating copy to clipboard operation
food2fork-compose copied to clipboard

fix (when initailly there is no internet connection)

Open milon27 opened this issue 3 years ago • 6 comments

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

milon27 avatar Jul 07 '21 21:07 milon27

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

mitchtabian avatar Jul 07 '21 21:07 mitchtabian

Pixel_4a_API_30

milon27 avatar Jul 07 '21 21:07 milon27

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

mitchtabian avatar Jul 07 '21 21:07 mitchtabian

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

milon27 avatar Jul 07 '21 21:07 milon27

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 .

mitchtabian avatar Jul 07 '21 22:07 mitchtabian

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

milon27 avatar Jul 07 '21 22:07 milon27