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

Android 10 ( 29 ) is not supported - Connect to network, enable, disable and more..

eliadAfeka opened this issue · comments

Prerequisites

Check all boxes if you have done the following:

Issue type

Select all that apply

  • Bug
  • Enhancement
  • Task
  • Question
  • Other

Description

some actions will not be supported in Android 10 due to some Android major upgrades in their API

Steps to Reproduce

  1. set "android-targetSdkVersion" to "29" in config.xml
  2. run your app on an Android 10 device. (it will not be reproduced if your device has <Android 10)
  3. try the following actions which will get errors:
  • Disable wifi
  • Enable wifi
  • Connect to network

Expected behavior: success

Actual behavior: Get errors

Reproduces how often: 100%

Versions

Please include the plugin version that you are using and also include the OS, version and device you are using.

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

For me it helped setting "android-targetSdkVersion" to 28 and to manually enable GPS on the phone. Which seems to work as a workaround for now...

it will not work for you from November 2020.

I have a working version running on Android 10. I modified it by forking https://github.com/ViggoChavine/WifiWizard2 who already started work for API 29 and i added on top of it for my app feel free to use as a base or as is: https://github.com/VijayVaveHealth/WifiWizard2/.
For ViggoChavine you have to manually call the add and enable functions. I modified my connect function slightly so you can just do WifiWizard2.connect(wifi.SSID, false, wifi.password, 'WPA')

On Android 29 there is a bug on certain devices, so far i've seen it on Oneplus 6 and a Nokia android phone the connection dialog comes up and gets stuck in a loop. If you read stackoverflow or other websites users mention seeing this on some of their devices, there is also a google issue ticket that was started but no update so far, seems phone vendors are at fault here. It works fine on the Pixel and Samsung phones.

hi,

@VijayVaveHealth - after installing your version it seems like not working while trying to connect wifi.
I get a different error from what I had, but still can't connect. I get "CONNECT_FAILED_TIMEOUT"

@eliadAfeka i only call the WifiWizard2.connect and in my WifiWizard.js file you will see in the connect function the calls to the android code. Android 10 devices only call add and then don't do anything else.

`

             if(device.platform === "Android" && parseInt(device.version.split('.')[0]) >= 10){

                 // New method for Android Q does not support it add method already brings up dialog to join network

            } else {

                // Successfully updated or added wifiConfig

                cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll]);

            }`

@VijayVaveHealth so I don't understand. how can I connect with Andoird>=10?

@VijayVaveHealth Thanks for the fix, it worked on Android 10 on my Samsung device.
There seems to be another issue, when i'm connected to other network and trying to connect to new network from the list, it's always saying "CONNECT_FAILED_TIMEOUT". It worked when i'm not connected to any wifi.
Should i disconnect before calling connect?

@laxman-spidey it turned to be that there is no support in WPA2, just use WPA instead and it will work.

@VijayVaveHealth can merge your commits?

@VijayVaveHealth your branch works perfect for me. This actually also gives me a succes back and doesn't keep hanging.
But actually it doesn't give me an error.

So when the network is not available it keeps loading any fix for this?

@VijayVaveHealth thanks for your work on implementing API level 29, unfortunately on Ionic 3 I receive a strange pop up saying "Searching for devices..." when I attempt to connect to a network via the connect or add method.
Eventually it will timeout giving me the option to cancel or retry. Interestingly, if I cancel, it reveals a pop up behind displaying my typical WiFiWizard2 connection message, but this never resolves.

This also happens with using the master branch of triplfex's repo which contains ViggoChavine's API 29 fixes (I have even tried other forks with API 29 support such as TMAEDCC, but I always have the same result).

I am using a Pixel 4 with Android 11.

I also saw that a few people started working on this but actually no success.

https://github.com/Pankaja13/WifiWizard2/tree/android-29 here the issue is it keeps looping and popping up the connection box.

https://github.com/ScottWaring/WifiWizard2/tree/android-ten-test This looked promising but when I add it to my project I get lots of errors so no succes

@HusFNS from what I can tell, almost all of the methods used in WifiWizard2 were deprecated. It seems that using WifiNetworkSuggestion might be the way forward now, but is only seems to support networks without an active internet connection (I assume it is intended purely for IoT).

Source: https://developer.android.com/guide/topics/connectivity/wifi-suggest#java

However, this may work in conjunction with above: https://developer.android.com/reference/android/provider/Settings?hl=en#ACTION_WIFI_ADD_NETWORKS

This plugin (https://github.com/sushichop/cordova-plugin-wifi-manager) does appear to work on my Pixel 4 running Android 11, however it does not have offer functionality such as scanning for nearby networks.

For now, I can run both plugins in order to achieve my goals, put perhaps the method used in cordova-plugin-wifi-manager can help with WifiWizard2's adoption of API level 29+.

@HusFNS That fork was really intended for a specific project I am working on but there's no reason it shouldn't work. I did have trouble getting that promise returned on success so I added a less than perfect workaround. Here's how I'm using in on > Android 10:

WifiWizard2.connect("SSID", true, "Password", "WPA").catch((e) => {
	if (e.toString() === "onUnavailable"){
		// Failure (or user clicked cancelled)
	}
	WifiWizard2.getConnectedSSID().then((SSID) => {
		// Success
	})
});

@HusFNS That fork was really intended for a specific project I am working on but there's no reason it shouldn't work. I did have trouble getting that promise returned on success so I added a less than perfect workaround. Here's how I'm using in on > Android 10:

WifiWizard2.connect("SSID", true, "Password", "WPA").catch((e) => {
	if (e.toString() === "onUnavailable"){
		// Failure (or user clicked cancelled)
	}
	WifiWizard2.getConnectedSSID().then((SSID) => {
		// Success
	})
});

I can confirm this works with Ionic 3 on a Pixel 4 with Android 11 - thanks!

I have been working on a fix and can be tested. It works fine for me on my android 10 (samsung).

The reason why he doesn't always return onUnavailable is because it is a bug in android. I made a workaround with a timout.
The available now returns success

Hi, I was facing same issue on my device OnePlus 6T with Android 10 and i wasn't able to connect through selected ssid.
So after 2-3 days i got to know that you have to turn on your GPS before connecting to wifi network. And this method works for me Hopefully this will work for you as well.

I'm able to connect to networks now again thanks to @maxcodefaster's fork, thank you!

But is it correct the wi-fi doesn't automatically turn on anymore if it's turned off? Does anybody know if there is a way to still programatically turn on wi-fi?

@KinG-InFeT this was indeed what I said. That's why I used the workaround with the de timeout.

I see @maxcodefaster used my fix and made a merge request for the master branch.

commented

Yes MR is inspired by @HusFNS

I'm able to connect to networks now again thanks to @maxcodefaster's fork, thank you!

But is it correct the wi-fi doesn't automatically turn on anymore if it's turned off? Does anybody know if there is a way to still programatically turn on wi-fi?

How do you do it?
I'm doing it like this and I get WiFi not available

WifiWizard2.connect("myssid", true, "", "", false)
      .then((data) => {

      })
      .catch(async (error) => {          

     
      });

yes, i use this commit

@KinG-InFeT this was indeed what I said. That's why I used the workaround with the de timeout.

I see @maxcodefaster used my fix and made a merge request for the master branch.

yes, i use the new fix with timeout but out UnAvailable, i tried add more timeout but not work. My device is Samsung Tab S6 Lite Android 10

I'm able to connect to networks now again thanks to @maxcodefaster's fork, thank you!
But is it correct the wi-fi doesn't automatically turn on anymore if it's turned off? Does anybody know if there is a way to still programatically turn on wi-fi?

How do you do it?
I'm doing it like this and I get WiFi not available

WifiWizard2.connect("myssid", true, "", "", false)
      .then((data) => {

      })
      .catch(async (error) => {          

     
      });

yes, same error

the PR is #115

Like this @KinG-InFeT and @1x2x3x4x

WifiWizard2.connect(SSID, true, password, 'WPA').then((success) => {
       ...
    }).catch((error) => {
        ...
    });

Like this @KinG-InFeT and @1x2x3x4x

WifiWizard2.connect(SSID, true, password, 'WPA').then((success) => {
       ...
    }).catch((error) => {
        ...
    });

yes, this is my code

WifiWizard2.connect(ssid, true, password, algorithm, false).then(() => {
                                    app.dialog.alert('Connessione riuscita');
                                }).catch((error) => {
                                    console.warn(error);
                                    app.dialog.close();
                                    var errMsg = error && error.message ? error.message : error;
                                    app.dialog.alert(errMsg);
                                });

(use framework7 latest version)

i found this project and work perfectly on my table with android 10: https://github.com/Tasssadar/RequestNetworkRepro but write in Kotlin

Did anyone encounter the following errors on Android 10?

I/WifiService: addOrUpdateNetwork not allowed for uid=10773
I/WifiService: getConfiguredNetworks not allowed for uid=10773
E/WifiService: 10164 has no permission about LOCAL_MAC_ADDRESS

https://github.com/sushichop/cordova-plugin-wifi-manager seems to work though, what could be the difference?

I've finally managed to get it to work like this on Android 10, Samsung s20 and a Samsung tablet. No luck on One Plus 5T but that's their fault, not the plugin's. I've used maxcodefaster's repo.

WifiWizard2.connect('mySSID', true, '', 'WPA').catch((e) => {
    if (e.toString() === "onUnavailable") {
        alert(e.toString())
    }
    WifiWizard2.getConnectedSSID().then((SSID) => {
        alert(SSID)
    })
});

However for some reason it won't work on a Xiaomi with Android 9.

I am having the same problem tried WifiWizard2.connect not working on Android 10 (APK-29), it is working fine on APK-28.
I am using Ionic 3 this is my implementation.

`declare var WifiWizard2: any;

  WifiWizard2.connect("ssid", true, "password", "WPA").catch((e) => {
    if (e.toString() === "onUnavailable"){
        this.perror = e.toString();
      // Failure (or user clicked cancelled)
    }
    WifiWizard2.getConnectedSSID().then((SSID) => {
      // Success
      this.pdone = JSON.stringify(SSID);
    })

`
any help ?

I have the fine location permission also, but I can't grant background permission

this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION);

it appears that my problem is with Ioinc 3 and android core as I understand if anyone could make it work or have a solution for that please let me know.

this is my project's android version
<engine name="android" spec="~7.1.4" />

this is the error while building
ifiWizard2.java:44: error: cannot find symbol import android.net.wifi.WifiNetworkSpecifier; ^

Hello children for I have returned.

I have merged PR #115 (there needs to be one or two changes since I was a bit gun-hoe on the merge).

@arsenal942 I'm excited to see this finally merged, thank you!! 😍

I am wondering if changing the URL of the repository in package.json and plugin.xml (see https://github.com/tripflex/WifiWizard2/pull/115/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R13) is intended? 🤔

@xLarry I have fixed it

This has finally been merged and therefore can be closed :)

I have a working version running on Android 10. I modified it by forking https://github.com/ViggoChavine/WifiWizard2 who already started work for API 29 and i added on top of it for my app feel free to use as a base or as is: https://github.com/VijayVaveHealth/WifiWizard2/.
For ViggoChavine you have to manually call the add and enable functions. I modified my connect function slightly so you can just do WifiWizard2.connect(wifi.SSID, false, wifi.password, 'WPA')

On Android 29 there is a bug on certain devices, so far i've seen it on Oneplus 6 and a Nokia android phone the connection dialog comes up and gets stuck in a loop. If you read stackoverflow or other websites users mention seeing this on some of their devices, there is also a google issue ticket that was started but no update so far, seems phone vendors are at fault here. It works fine on the Pixel and Samsung phones.

I am having the same loop issue on Android 29 on my Oneplus 6t, it connects for a second and then disconnects again.
Any updates regarding this?

I am having the same loop issue on Android 29 on my Oneplus 6t, it connects for a second and then disconnects again.
Any updates regarding this?

That error has nothing to do with the plugin. It's your OS's fault. You can go and read about it on OnePlus'es forums.

Just google 'oneplus WifiNetworkSpecifier'.

You'll just have to wait and see if any future update from oneplus will fix it.

I'm able to connect to networks now again thanks to @maxcodefaster's fork, thank you!
But is it correct the wi-fi doesn't automatically turn on anymore if it's turned off? Does anybody know if there is a way to still programatically turn on wi-fi?

How do you do it?
I'm doing it like this and I get WiFi not available

WifiWizard2.connect("myssid", true, "", "", false)
      .then((data) => {

      })
      .catch(async (error) => {          

     
      });

Did you find any solution for 'WiFi not available' ? I am getting the same error. I am currently using master branch on android 10.

Did you find any solution for 'WiFi not available' ? I am getting the same error. I am currently using master branch on android 10 OnePlus

I stoppped using this in my projects. I'm using Capacitor and works so far on the latst versions of Android and iOS: https://github.com/digaus/community-capacitor-wifi

So the solution is simply adding location permission to the app. You can ask for it from the app, or you can test it by going to your app settings -> permissions -> location and clicking