简体   繁体   中英

How to display WiFi network (SSID) list on react native app using expo?

Is there a way to display all Wifi list in react native using expo for Android. I have seen a few libraries but mostly for android and even those don't work properly. Any suggestions?

I want like :

在此处输入图像描述

use this library and this the code give you (SSID) list

getWifiNetworksOnPress(){
wifi.loadWifiList((wifiStringList) => {
    console.log(wifiStringList);
    var wifiArray = JSON.parse(wifiStringList);
   console.log(wifiArray);
  },
  (error) => {
    console.log(error);
  }
);

}

but in Android Api >25 you must be granted the ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) permission in order to obtain results.

I'm also facing this issue. But now I have got a Library that solves my problem.

Just visit [react-native-wifi-reborn][1].

Usage

import WifiManager from "react-native-wifi-reborn";

WifiManager.connectToProtectedSSID(ssid, password, isWep).then(
   () => {
     console.log("Connected successfully!");
   },
   () => {
     console.log("Connection failed!");
   }
 );

 WifiManager.getCurrentWifiSSID().then(
   ssid => {
     console.log("Your current connected wifi SSID is " + ssid);
   },
   () => {
     console.log("Cannot get current SSID!");
   }
 );

I hope it will work. [1]: https://www.npmjs.com/package/react-native-wifi-reborn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM