From 2293de1160f5168a7a3644fa5a72386a57be0d67 Mon Sep 17 00:00:00 2001 From: Gregorio Date: Thu, 27 Jun 2024 15:21:41 -0300 Subject: [PATCH] Add isOnline helper --- WalletSdk/src/main/AndroidManifest.xml | 3 ++- .../java/com/spruceid/wallet/sdk/Utils.kt | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/WalletSdk/src/main/AndroidManifest.xml b/WalletSdk/src/main/AndroidManifest.xml index 7a467ff..1fa894b 100644 --- a/WalletSdk/src/main/AndroidManifest.xml +++ b/WalletSdk/src/main/AndroidManifest.xml @@ -15,5 +15,6 @@ - + + \ No newline at end of file diff --git a/WalletSdk/src/main/java/com/spruceid/wallet/sdk/Utils.kt b/WalletSdk/src/main/java/com/spruceid/wallet/sdk/Utils.kt index 01127a6..38e9acd 100644 --- a/WalletSdk/src/main/java/com/spruceid/wallet/sdk/Utils.kt +++ b/WalletSdk/src/main/java/com/spruceid/wallet/sdk/Utils.kt @@ -27,4 +27,26 @@ enum class PresentmentState { /// App should display a success message and offer to close the page SUCCESS, -} \ No newline at end of file +} + +fun isOnline(context: Context): Boolean { + val connectivityManager = + context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + if (connectivityManager != null) { + val capabilities = + connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork) + if (capabilities != null) { + if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { + Log.i("Internet", "NetworkCapabilities.TRANSPORT_CELLULAR") + return true + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + Log.i("Internet", "NetworkCapabilities.TRANSPORT_WIFI") + return true + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) { + Log.i("Internet", "NetworkCapabilities.TRANSPORT_ETHERNET") + return true + } + } + } + return false +}