File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
kotlin-utils/src/main/java/com/costular/kotlin_utils/network Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.costular.kotlin_utils.network
2+
3+ import android.content.Context
4+ import android.net.ConnectivityManager
5+ import android.net.NetworkInfo
6+ import com.costular.kotlin_utils.manager.getConnectivityManager
7+
8+ /* *
9+ * Created by costular on 14/08/17.
10+ */
11+ fun Context.isNetworkAvailable (): Boolean {
12+ val state = getConnectivityManager().activeNetworkInfo.state
13+ return (state == NetworkInfo .State .CONNECTED || state == NetworkInfo .State .CONNECTING )
14+ }
15+
16+ fun Context.getNetworkType (): Int = getConnectivityManager().activeNetworkInfo.type
17+
18+ fun Context.getNetworkTypeAsString (): String {
19+ when (getConnectivityManager().activeNetworkInfo.type) {
20+ ConnectivityManager .TYPE_WIFI -> return " WiFi"
21+ ConnectivityManager .TYPE_MOBILE -> return " Mobile"
22+ else -> return " "
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments