{"id":1606,"date":"2017-07-26T10:42:48","date_gmt":"2017-07-26T10:42:48","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=1606"},"modified":"2021-09-08T19:06:36","modified_gmt":"2021-09-08T13:36:36","slug":"react-native-manage-wifi-android","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/","title":{"rendered":"React Native &#8211; \u200aManage wifi on Android"},"content":{"rendered":"\n<p>I am working on a <a href=\"https:\/\/www.botreetechnologies.com\/react-native-development\" target=\"_blank\" rel=\"noreferrer noopener\">React Native app<\/a> and there was a need to manage a Wifi network on the device. It needed to do the following,<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Verify if the mobile WIFI is enabled or not<\/li><li>Fetch the WIFI network list<\/li><li>Connect with the selected WIFI from the list<\/li><li>Disconnect the WIFI<\/li><li>Forget the WIFI network from the mobile<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Approach&#8230;<\/h3>\n\n\n\n<p>So first I looked at the React Native docs and found the\u00a0NetInfo\u00a0class which allows to access the Wifi on the native OS. But, when I looked at it closely, I found that it only checks the following,<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Device is connected with internet<\/li><li>Connection type if the device is connected, otherwise &#8216;none&#8217;<\/li><\/ul>\n\n\n\n<p>It does not allow to manage the WIFI! Now what!<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8220;When it&#8217;s not supported in React Native, we look at the Native OS&nbsp;API!&#8221;<\/p><\/blockquote>\n\n\n\n<p>Then I looked at what native Android integration bridges are available for wifi, and found the package <a href=\"https:\/\/github.com\/BoTreeConsultingTeam\/react-native-android-wifi\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">react-native-android-wifi<\/a>. This module requires the following permission on the Android platform, which we can configure in the&nbsp;<code>AndroidManifest.xml<\/code><\/p>\n\n\n\n<p><code>&lt;uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\" \/&gt;<br>\n&lt;uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\" \/&gt;<br>\n&lt;uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\" \/&gt;<br>\n&lt;uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"\/<\/code><br>After installation, I have used it as following,<br><code>var wifi = require('react-native-android-wifi');<\/code><br><code>\/\/Is the wifi is enabled or disabled?<br>\nwifi.isEnabled((isEnabled)=&gt;{<br>\nif (isEnabled){<br>\nconsole.log(\"wifi service enabled\");<br>\n}else{<br>\nconsole.log(\"wifi service is disabled\");<br>\n}<br>\n});<\/code><\/p>\n\n\n\n<p>I also wanted to forget\/remove the wifi network from my mobile&#8217;s wifi network list and forcefully re-scan the wifi network list from the app itself. But, these were not implemented in the original sourcecode.<\/p>\n\n\n\n<p>So I have added these new APIs as following, in the forked repo.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Remove \/ Forget the Wifi network from mobile by SSID, returns&nbsp;boolean<\/h3>\n\n\n\n<p><code>wifi.isRemoveWifiNetwork(ssid, (isRemoved) =&gt; {<br>\nconsole.log(\"Forgetting the wifi device - \" + ssid);<br>\n});<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Starts native Android wifi network scanning and returns list<\/h3>\n\n\n\n<p><code>wifi.reScanAndLoadWifiList((wifiStringList) =&gt; {<br>\nvar wifiArray = JSON.parse(wifiStringList);<br>\nconsole.log('Detected wifi networks - ',wifiArray);<br>\n});<\/code><\/p>\n\n\n\n<p>There are other APIs which you can check at&nbsp;<a href=\"https:\/\/github.com\/BoTreeConsultingTeam\/react-native-android-wifi\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" data-href=\"https:\/\/github.com\/BoTreeConsultingTeam\/react-native-android-wifi\">https:\/\/github.com\/BoTreeConsultingTeam\/react-native-android-wifi<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p>At <a href=\"https:\/\/www.botreetechnologies.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">BoTree Technologies<\/a>, we build enterprise applications with our React Native team of 10+ engineers.<\/p>\n\n\n\n<p>We also specialize in Ruby on Rails, Python, RPA, AI, Django, NodeJS and ReactJS.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.botreetechnologies.com\/contact\" target=\"_blank\" rel=\"noopener noreferrer\">Consulting is free<\/a>&nbsp;\u2013 <strong>let us help you grow!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am working on a React Native app and there&#8230;<\/p>\n","protected":false},"author":6,"featured_media":12975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72,10],"tags":[],"class_list":["post-1606","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-native","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>React Native - \u200aManage wifi on Android<\/title>\n<meta name=\"description\" content=\"Learn how to manage WiFi network on a device by React Native app. For more queries on React Native contact BoTree Technologies.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Native - \u200aManage wifi on Android\" \/>\n<meta property=\"og:description\" content=\"Learn how to manage WiFi network on a device by React Native app. For more queries on React Native contact BoTree Technologies.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-26T10:42:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-08T13:36:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1333\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Parth Barot\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Parth Barot\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\"},\"author\":{\"name\":\"Parth Barot\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f\"},\"headline\":\"React Native &#8211; \u200aManage wifi on Android\",\"datePublished\":\"2017-07-26T10:42:48+00:00\",\"dateModified\":\"2021-09-08T13:36:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\"},\"wordCount\":311,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png\",\"articleSection\":[\"React Native\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\",\"name\":\"React Native - \u200aManage wifi on Android\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png\",\"datePublished\":\"2017-07-26T10:42:48+00:00\",\"dateModified\":\"2021-09-08T13:36:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f\"},\"description\":\"Learn how to manage WiFi network on a device by React Native app. For more queries on React Native contact BoTree Technologies.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png\",\"width\":2000,\"height\":1333,\"caption\":\"manage wifi on android\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Native &#8211; \u200aManage wifi on Android\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f\",\"name\":\"Parth Barot\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png\",\"caption\":\"Parth Barot\"},\"description\":\"Parth is the co-founder and CTO at BoTree Technologies. He has worked on building products in different domains and technologies. He is now managing research and pre-sales by supporting it with his problem-solving approach.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"React Native - \u200aManage wifi on Android","description":"Learn how to manage WiFi network on a device by React Native app. For more queries on React Native contact BoTree Technologies.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/","og_locale":"en_US","og_type":"article","og_title":"React Native - \u200aManage wifi on Android","og_description":"Learn how to manage WiFi network on a device by React Native app. For more queries on React Native contact BoTree Technologies.","og_url":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2017-07-26T10:42:48+00:00","article_modified_time":"2021-09-08T13:36:36+00:00","og_image":[{"width":2000,"height":1333,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png","type":"image\/png"}],"author":"Parth Barot","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Parth Barot","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/"},"author":{"name":"Parth Barot","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f"},"headline":"React Native &#8211; \u200aManage wifi on Android","datePublished":"2017-07-26T10:42:48+00:00","dateModified":"2021-09-08T13:36:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/"},"wordCount":311,"commentCount":0,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png","articleSection":["React Native","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/","url":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/","name":"React Native - \u200aManage wifi on Android","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png","datePublished":"2017-07-26T10:42:48+00:00","dateModified":"2021-09-08T13:36:36+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f"},"description":"Learn how to manage WiFi network on a device by React Native app. For more queries on React Native contact BoTree Technologies.","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/manage-wifi-on-android.png","width":2000,"height":1333,"caption":"manage wifi on android"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/react-native-manage-wifi-android\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"React Native &#8211; \u200aManage wifi on Android"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/1952b3c6679346e5a2792581a67b1b0f","name":"Parth Barot","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/parth-barot-150x150.png","caption":"Parth Barot"},"description":"Parth is the co-founder and CTO at BoTree Technologies. He has worked on building products in different domains and technologies. He is now managing research and pre-sales by supporting it with his problem-solving approach."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=1606"}],"version-history":[{"count":2,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1606\/revisions"}],"predecessor-version":[{"id":16257,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/1606\/revisions\/16257"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/12975"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=1606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=1606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=1606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}