Implemented getting network IF info (routes) via Kotlin
This commit is contained in:
parent
ca6e4b8802
commit
6be08026c0
1 changed files with 3 additions and 5 deletions
|
@ -7,11 +7,11 @@ import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
|
|
||||||
object NetworkHelper {
|
object NetworkHelper {
|
||||||
fun setRoutes(context: Context) {
|
fun getRoutes(context: Context): String {
|
||||||
val connectivity =
|
val connectivity =
|
||||||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
|
||||||
val lp = connectivity.getLinkProperties(connectivity.activeNetwork) ?: return
|
val lp = connectivity.getLinkProperties(connectivity.activeNetwork) ?: return ""
|
||||||
|
|
||||||
val ifName = lp.interfaceName
|
val ifName = lp.interfaceName
|
||||||
val addr = lp.linkAddresses[0]
|
val addr = lp.linkAddresses[0]
|
||||||
|
@ -28,8 +28,6 @@ object NetworkHelper {
|
||||||
|
|
||||||
val gw = lp.routes.last { it.isDefaultRoute }.gateway?.hostAddress
|
val gw = lp.routes.last { it.isDefaultRoute }.gateway?.hostAddress
|
||||||
|
|
||||||
val settingFormattedRoute = "$ifName;$addr;$mask;$gw"
|
return "$ifName;$addr;$mask;$gw"
|
||||||
|
|
||||||
// TODO set this value to settings
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue