I am making an app to control the device, I use react-native-wifi-reborn to connect to a hidden wifi, but when I call the connect function, the phone asks for permission to change wifi and I click allow, but after that, the permission request is repeated until the wifi connects wifi, the requesting permission stops.
How can I fix this error. Looking forward to everyone's help !. Thank you!
My english is not good, looking forward to your help!
i'm using:
react-native: 0.60.5,
react-native-wifi-reborn: 4.3.4,
Here is the picture asking for permission and the code you use to connect.
onPressChangeWifi = async() => {
const checkpermission = await PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
)
if(!checkpermission){
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Location permission is required for WiFi connections',
message:
'This app needs location permission as this is required ' +
'to scan for wifi networks.',
buttonNegative: 'DENY',
buttonPositive: 'ALLOW',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// You can now use react-native-wifi-reborn
connectToWifi()
} else {
// Permission denied
}
}else{
connectToWifi()
}
}
const connectToWifi = () => {
WifiManager.connectToProtectedSSID('MarsWiFi4282', '123567890' , false).then(
() => {
console.warn("Connected successfully!");
},
() => {
console.warn("Connection failed!");
}
);
WifiManager.getCurrentWifiSSID().then(
ssid => {
console.warn("Your current connected wifi SSID is " + ssid);
},
() => {
console.warn("Cannot get current SSID!");
}
);
}
