How do I see if Wi-Fi is connected on Android?

前端 未结 22 2629
挽巷
挽巷 2020-11-22 05:56

I don\'t want my user to even try downloading something unless they have Wi-Fi connected. However, I can only seem to be able to tell if Wi-Fi is enabled, but they could sti

22条回答
  •  被撕碎了的回忆
    2020-11-22 06:13

    Similar to @Jason Knight answer, but in Kotlin way:

    val connManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    val mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
    
    if (mWifi.isConnected) {
         // Do whatever
    }
    

提交回复
热议问题