hoerresb / WifiWizard

A Cordova plugin for managing Wifi networks
Apache License 2.0
205 stars 178 forks source link

getScanResults not working on Nexus 5 with Android 6.0.1 #90

Open llioor opened 8 years ago

llioor commented 8 years ago

Hi, The plugin works wonderfully (setWifiEnabled, addNetwork, connectNetwork, disconnectNetwork, etc.)

startScan calls the success callback, but getScanResults always calls the success callback with an empty array.

we have used an androidManifest with the following pemissions:

 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Any ideas?

llioor commented 8 years ago

@hoerresb Any chance to get an answer please?

leitzsin360 commented 8 years ago

AFTER enable GPS .it is ok. Its a bug in Andorid 6+

llioor commented 8 years ago

Even with GPS enabled it is not working.. getScanResults still calls the success callback with an empty array. Any advice?

leitzsin360 commented 8 years ago

I test ok. and I commented the following lines in file WifiWizard.java

// // // if(!displayLocationSettingsRequest()){ // callbackContext.error("Android 6 and above Gps turned off"); // } // // if(!checkCurrentPermissions()){ // callbackContext.error("permission not found") ; // }

leitzsin360 commented 8 years ago

I tested ok. and I commented the following lines in file WifiWizard.java

// // // if(!displayLocationSettingsRequest()){ // callbackContext.error("Android 6 and above Gps turned off"); // } // // if(!checkCurrentPermissions()){ // callbackContext.error("permission not found") ; // }

leitzsin360 commented 8 years ago

I tested ok. and I commented the following lines in file WifiWizard.java

// // // if(!displayLocationSettingsRequest()){ // callbackContext.error("Android 6 and above Gps turned off"); // } // // if(!checkCurrentPermissions()){ // callbackContext.error("permission not found") ; // }

digitalWestie commented 8 years ago

hey, I've got the same issue here Nexus 5 with Android 6.0.1

digitalWestie commented 8 years ago

OK, I turned my GPS on and it didn't work. But when I went into Settings -> App -> My App -> Permissions and allowed location it worked. Very odd one.

byrcz17 commented 7 years ago

hey, this problem is solved?? I try run in android 6.x with turned GPS, and it didn't work... Any idea?

emcniece commented 7 years ago

Just worked through this - manually enabling the Location permission as @digitalWestie mentioned made the networks show up.

The branch at https://github.com/paraggarg37/WifiWizard contains a check for GPS enable, but the app itself doesn't complain when Location is off. I'm going to try and use http://ionicframework.com/docs/v2/native/diagnostic/ to see if I can get a better indication of available services.

zhangdongming0607 commented 7 years ago

Well,I tried with xiaomi5. At first,I got an empty array as well.But when the access of using location and wifi is allowed ,I can get the correct list. Just like @emcniece says ,manually enable the access to location and wifi is necessary(default is ask when used).

peeter-tomberg commented 7 years ago

You have to ask for permissions at runtime. I used the plugin https://github.com/dpa99c/cordova-diagnostic-plugin to achieve this. Before calling getScanResults, I call window.cordova.plugins.diagnostic.requestLocationAuthorization(successCallback, errorCallback);

Please note that successCallback does not mean the user granted you permissions, it might also mean the user denied your permission. Read more at: https://github.com/dpa99c/cordova-diagnostic-plugin#requestlocationauthorization

tyleha commented 7 years ago

Confirmed that I needed to enable Location permissions in Android 6.0.1 to get getScanResults to work. I now request these permissions programatically with cordova-plugin-android-permissions

RavikiranCK commented 7 years ago

@leitzsin360 That was pain before I got to know the fact..Thank you for saving my head..Pretty frustrating when there's no exception or things go normally without expected output..

pflugs30 commented 6 years ago

@peeter-tomberg I'm trying to do what you described in your comment on Android version 7.0.0. However, I'm getting a "Permission permanently denied" response on the call to requestLocationAuthorization. Did you encounter anything like that?

I also notice that the phone never prompts me to enable the permission. I'm currently testing my app using cordova run android via USB debugging. I was also unable to find my app in the settings to manually enable the permissions. I suspect (thought I don't know for sure) I am being blocked by not having the app actually installed on my device, just debugging via cordova. Any ideas on what to check? Thank you.

StrongLucky commented 6 years ago

@pflugs30 I just had the same problem. But I found my problem. I clickt "never show again". I fully deinstalled the app. Now the app ask again. Maybee this will help you.

To request the permission is only run diagnostic.requestLocationAuthorization()

mhossam2008 commented 5 years ago

You have to make sure that your app is using both coarse and fine location permissions and make sure that wifi "and GPS surprisingly" is turned on , that's an odd bug , but that's how things worked for me after couple of hours of trouble shooting