{"id":3624,"date":"2020-11-05T07:04:02","date_gmt":"2020-11-05T13:04:02","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=3624"},"modified":"2020-11-05T07:05:30","modified_gmt":"2020-11-05T13:05:30","slug":"getting-android-wifi-state-in-kotlin","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/getting-android-wifi-state-in-kotlin\/","title":{"rendered":"Getting Android WiFi state in Kotlin"},"content":{"rendered":"\n<p>In Kotlin you can request if the WiFi adapter is on or off with the following code<br><em>This changes the text on a textbox, replace with your textbox.<\/em><\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"php\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">wifiManager = this.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager\ntextBox.text = \"WiFi State = ${wifiManager.wifiState}\"\n<\/pre><\/div>\n\n\n\n<p>The important part is <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wifiManager.<em>wifiState<\/em><\/pre>\n\n\n\n<p>It will return a number from 0-4 which indicates if it is on or off.<\/p>\n\n\n\n<p>0 = WiFi is being disabled<br>1 = WiFi Disabled<br>2 = WiFi is being enabled<br>3 = WiFi is Enabled<br>4 = Error<\/p>\n\n\n\n<p><a href=\"https:\/\/developer.android.com\/reference\/kotlin\/android\/net\/wifi\/WifiManager#WIFI_STATE_DISABLED:kotlin.Int\">https:\/\/developer.android.com\/reference\/kotlin\/android\/net\/wifi\/WifiManager#WIFI_STATE_DISABLED:kotlin.Int<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Kotlin you can request if the WiFi adapter is on or off with the following codeThis changes the text on a textbox, replace with your textbox. The important part is wifiManager.wifiState It will return a number from 0-4 which &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/getting-android-wifi-state-in-kotlin\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[540,792],"tags":[541,1064,606,1101,114,1103,1102],"class_list":["post-3624","post","type-post","status-publish","format-standard","hentry","category-android","category-programming","tag-android","tag-kotlin","tag-programming","tag-state","tag-wifi","tag-wifimanager","tag-wifistate"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=3624"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3624\/revisions"}],"predecessor-version":[{"id":3627,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3624\/revisions\/3627"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=3624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=3624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=3624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}