Skip to content

Commit

Permalink
Add isOnline helper
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ll3 committed Jun 27, 2024
1 parent 970cf58 commit 2293de1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion WalletSdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
24 changes: 23 additions & 1 deletion WalletSdk/src/main/java/com/spruceid/wallet/sdk/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,26 @@ enum class PresentmentState {

/// App should display a success message and offer to close the page
SUCCESS,
}
}

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
}

0 comments on commit 2293de1

Please sign in to comment.