tripflex / WifiWizard2

A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+

Home Page:https://www.npmjs.com/package/cordova-plugin-wifiwizard2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getConnectedSSID() return unknown ssid in some mobile devices

gorebill opened this issue · comments

commented

Prerequisites

Check all boxes if you have done the following:

Issue type

Select all that apply

  • Bug
  • Enhancement
  • Task
  • Question
  • [] Other

Description

My customer reported that his android shows in app but I can't reproduce it in my devices and emulator whatever android versions. Coincidently, I found some one post a blog that a similar issue for some mobile device - vivo x21iA / vivo x20.

I've tested in these two devices and the issue surely could be reproduced.
It's undoubtedly not the bug of plugin. It should be a bug of some firmwares or else, but I can't tell my customers to contact the mobile manufacturer to solve this problem.

Thus, I have modified the code(WifiWizard2.java) as below(get SSID by another API):

      serviceInfo = info.getSSID();

      if(serviceInfo != null && serviceInfo.contains("unknown ssid")) {
          NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
          String wifiName = wifiInfo.getExtraInfo();
          if (wifiName.startsWith("\"")) {
              wifiName = wifiName.substring(1, wifiName.length());
          }
          if (wifiName.endsWith("\"")) {
              wifiName = wifiName.substring(0, wifiName.length() - 1);
          }
          serviceInfo = wifiName;
      }

And it works now. Hope this would help someone.

Versions

vivo x21iA / vivo x20 and maybe more
Android 8.1
WifiWizard2 3.x

@gorebill You may wanna try calling WifiWizard2.requestPermission() manually. In your case info.requestPermission(). Experienced the same while using android 8.1+

@gorebill can you comment if @luisAzcuaga suggested fixes the issue you were having? If not, we can maybe look at adding a fallback method for obtaining it if nothing is returned from current one

Actually It worked but... not on every phone. Had issues using wifiwizard2.requestPermission() testing on my Nexus 7 2013 (with Android 4.4.4). So I started using androidPermissions because Android versions prior 6.0, don't have permissions (Android 4.0, 5.0).

I've tried modified version by gorebill and also use of permissions but not working on my device:
Asus_Z01QD (Rogue)
Android 8.1.0
build: OPM1.171019.026.WW_Phone-15.1630.1812.68-0

Some help ?

@blondie63 make sure you have Location/GPS turned on and test this. We're going to add a fallback method in the next update but until then 8.1.0+ requires the permissions, but even if perms are granted and GPS/Location is disabled, will not get same results

https://stackoverflow.com/questions/49977395/on-oreo-8-1-0-not-getting-the-correct-wifi-ssid-its-showing-unknown-ssid-t
https://developer.android.com/reference/android/net/wifi/WifiManager

@blondie63 make sure you have Location/GPS turned on and test this. We're going to add a fallback method in the next update but until then 8.1.0+ requires the permissions, but even if perms are granted and GPS/Location is disabled, will not get same results

https://stackoverflow.com/questions/49977395/on-oreo-8-1-0-not-getting-the-correct-wifi-ssid-its-showing-unknown-ssid-t
https://developer.android.com/reference/android/net/wifi/WifiManager

Believe me, on my Asus i've "Location/GPS turned on" and request permissions before call SSID functions.. but you wrote:

WifiWizard2.getCurrentSSID returns unknown on Android 8.1 #13

WifiWizard2.getConnectedSSID() NOT working with Android >= 8.1 #67

So which function i can call on Android >= 8.1 to get SSID ?

@blondie63 Could you please show us a code fragment?

Finally i've fixed my code !
I've uploaded a demo project here: https://github.com/blondie63/CheckWIFI

@blondie63 AWESOME thank you for posting your code, this will most certainly help for debug and updating this library for ionic support, as well as a great example for others on how to use it with Ionic, will add it to the README as example app if you plan on leaving it online

@blondie63 AWESOME thank you for posting your code, this will most certainly help for debug and updating this library for ionic support, as well as a great example for others on how to use it with Ionic, will add it to the README as example app if you plan on leaving it online

Sure, i live it online and implementing it..

@blondie63 I'll give this a go this week as well, see how it works

This may be fixed by #72 going to push the update today and you guys can test to see if it fixes the problems.

@gorebill @blondie63 @simonkincaidkintronix you guys can try the dev branch which has handling added for location check lmk if it works for you

I just came accross this issue after experiencing the same issue on an Android 9 device and pulled the plugin from dev branch in order to see if that resolves the issue.

Good news is, getConnectedSSID() will return the expected SSID instead of "<unknown ssid>" after granting permissions 🎉

However, a message started to appear in the console, saying Incorrect action parameter: connect when calling WifiWizard2.connect(). My guess is, that this is caused by splitting up the if-else-if-else...-construct in WifiWizard2.java (Line 261). The second if-else-...-construct will enter the final else clause (given that the action is 'connect') and finally returns the above given error message.

@tripflex can you confirm these thoughts or am I doing something wrong on my side?

Btw: I really appreciate your great work and would like to donate, if possible. Let me know.

@xLarry ahhh okay thank you for testing this and reporting back your results, you are correct, splitting up the if-else statements causes it to return that error. The check for location should be moved into its own else statement, that way it's only ran when one of the other actions is not matched.

I updated this in df3cbe0 can you please check with this and let me know if this resolves the issue for you?