[Android/Kotlin] - Wifi ์ฐ๊ฒฐ ์ํ ํ์ธํ๊ธฐ
2020. 12. 30. 19:02ใ๐ฑAndroid/๐ Android Study
๋ฐ์ํ
๊ถํ ์ค์ ํ๊ธฐ
Network ๊ถํ์ ์ค์ ํด์ฃผ๋ permission์ ์ถ๊ฐํด์ฃผ์ธ์!
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
์ฌ์ฉ๋ฒ
ConnectionManager๋ฅผ ํตํด Network Wifi ์ํ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค : )
// ์ธํฐ๋ท ์ฐ๊ฒฐ ํ์ธ ํจ์
fun getNetworkConnected(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork : NetworkInfo? = cm.activeNetworkInfo
val isConnected : Boolean = activeNetwork?.isConnectedOrConnecting == true
return isConnected
}
wifi & ์ ๋ฃฐ๋ฌ ์ฐ๊ฒฐ์ -> true ๋ฐํ
wifi & ์ ๋ฃฐ๋ฌ ์ฐ๊ฒฐ ์คํจ์ -> false ๋ฐํ
๋ฐ์ํ
'๐ฑAndroid > ๐ Android Study' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android/Kotlin] Splash ํ๋ฉด ๋ง๋ค๊ธฐ (0) | 2020.12.31 |
---|---|
[Android/Kotlin] - WebView ์ฌ์ฉํ๊ธฐ (0) | 2020.12.30 |
[Android] ํ์ผ .gitignore ์ ์ฉํ๊ธฐ (0) | 2020.11.22 |