WifiWizard2 icon indicating copy to clipboard operation
WifiWizard2 copied to clipboard

getConnectedSSID() return unknown ssid in some mobile devices

Open gorebill opened this issue 6 years ago • 15 comments

Prerequisites

Check all boxes if you have done the following:

  • [x] Checked that your issue isn't already filed: https://github.com/tripflex/wifiwizard2/issues
  • [x] Make sure you fill out the Issue Type below

Issue type

Select all that apply

  • [ ] Bug
  • [x] 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 avatar Dec 17 '18 11:12 gorebill

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

luisAzcuaga avatar Dec 18 '18 18:12 luisAzcuaga

@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

tripflex avatar Feb 07 '19 20:02 tripflex

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).

luisAzcuaga avatar Feb 07 '19 21:02 luisAzcuaga

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 avatar Feb 16 '19 14:02 blondie63

@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

tripflex avatar Feb 17 '19 18:02 tripflex

@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 avatar Feb 17 '19 19:02 blondie63

@blondie63 Could you please show us a code fragment?

luisAzcuaga avatar Feb 17 '19 20:02 luisAzcuaga

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

blondie63 avatar Feb 17 '19 22:02 blondie63

@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

tripflex avatar Feb 18 '19 20:02 tripflex

@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 avatar Feb 19 '19 00:02 blondie63

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

simonkincaidkintronix avatar Feb 20 '19 12:02 simonkincaidkintronix

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

tripflex avatar Apr 03 '19 15:04 tripflex

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

tripflex avatar Apr 04 '19 23:04 tripflex

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 avatar May 09 '19 13:05 xLarry

@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 https://github.com/tripflex/WifiWizard2/commit/df3cbe0031f0aacc01bdb901efc7629f7e1c87cf can you please check with this and let me know if this resolves the issue for you?

tripflex avatar Jun 23 '19 21:06 tripflex