https://kotlinlang.org logo
#feed
Title
# feed
m

magnumrocha

03/22/2024, 5:11 PM
Happy Friday everyone! Just released the version 1.2.0 of Konnection library with a new library target: JVM. So now, you can use Konnection on your Java target apps (desktop or web). https://github.com/TM-Apps/konnection
🔥 3
p

Pablichjenkov

03/22/2024, 5:51 PM
In Android does it use the new ConnectionRequests callback oriented API or relies on the deprecated synchronous WifiManager and ConnectivityManager APIs? Sorry for asking and not going through the code
m

magnumrocha

03/22/2024, 6:12 PM
high now, it's using ConnectivityManager, but I have plans to migrate but looking into documentation, the ConectivityManager is not deprecated https://developer.android.com/reference/android/net/ConnectivityManager
actually, the Android implementation has this:
Copy code
actual fun getCurrentNetworkConnection(): NetworkConnection? =
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        postAndroidMNetworkConnection(connectivityManager)
    } else {
        preAndroidMNetworkConnection(connectivityManager)
    }
p

Pablichjenkov

03/22/2024, 7:04 PM
No, is not fully deprecated, I mean some functions are deprecated not the full API. The synchronous functions were deprecated in favor of a callback API. It seems you are using the right ones. I went over the iOS code and I see the KConnection implementation you chose to throw an exception? Or was me not reading it well on my phone. I would suggest returning a ResultT rather than throws
s

Stefan Oltmann

03/22/2024, 7:30 PM
On JVM it tests if either Google, Amazon, Facebook or Apple homepages are available I wonder if using JNI receiving actual system information is available. That would be great. I do a connection check like this, too, but a real system query would be way better.
Great choice of name btw. 😄 💪
👍 1
m

magnumrocha

03/22/2024, 8:29 PM
regarding the JVM internet check method, I will try to improve this logic, but by what I saw many projects are using this approach of check well knows websites
s

Stefan Oltmann

03/22/2024, 9:08 PM
Yes, because it’s a simple strategy. Easy and fast to implement. The way better method would be asking the OS, but that’s not something you can do quickly if you are in a schedule. For a library doing this properly and also detecting the connection type would be a good place. If you offer that I would remove my custom logic from Ashampoo Photos and use your lib. It’s better information and more stable. Because even alone google going down the „ping“ solution is more like „good enough“, but not actually good.
Ashampoo Photos needs to sync data with cloud services (if people connected them). Based on the connection type (expensive mobile or „free“ WIFI) it decides on when and what to sync. Works good on iOS and Android as we have proper API. On Windows we just need to assume that it will not be a metered connection and hope for the best. 🫣
p

Pablichjenkov

03/22/2024, 9:20 PM
On my experience with the Android API it was a bit unreliable. The latest stuff recommended in the documentation. We ended up with the ping solution to a proprietary endpoint.
👀 1
s

Stefan Oltmann

03/22/2024, 9:22 PM
Interesting.
m

magnumrocha

03/22/2024, 9:23 PM
for Android implementation, I did many test with different scenarios and the current solution is working properly. I already use it on some Apps. But I understand that this depends on the Android version, I think it's more a system related thing than a SDK APIs related thing
there are many Android libraries that implement the ping solution
s

Stefan Oltmann

03/22/2024, 9:25 PM
Because the ping solution is quick and easy to implement with low effort.
For the ping solution a library is not even necessary. It can be done with Ktor very quick. 🤷‍♂️
The real value of a dedicated lib lies in information beyond "we are connected to the internet somehow".
m

magnumrocha

03/22/2024, 9:27 PM
just to be clear: my purpose with this library is to be as more as pure possible.
I'm investigating to improve the JVM approach
p

Pablichjenkov

03/22/2024, 9:28 PM
Yes, my problem was when switching networks. Either from WiFi to WiFi or WiFi to LTE
Sometimes the network callback didn't come 😢 Definitely impacted by the device diversity as well. Typical Android problem. So went for a straight forward solution.
s

Stefan Oltmann

03/22/2024, 9:31 PM
If you only need to know a boolean "connected" (or not) that's feasible
💯 1
a

Armond Avanes

03/23/2024, 5:10 AM
@magnumrocha Just a quick feedback. You should be able to utilize Jetpack "App Startup" library to get access to context on Android side... to unify the APIs on all platforms.
👍 1
m

magnumrocha

03/23/2024, 8:03 AM
interesting ideia @Armond Avanes, I'll check it, thank you
👍 1
3 Views