Skip to content

Commit 2b5eb38

Browse files
committed
ADD network utils
1 parent 0dc05a4 commit 2b5eb38

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)