tripflex / WifiWizard2

A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+
https://www.npmjs.com/package/cordova-plugin-wifiwizard2
Apache License 2.0
123 stars 146 forks source link

Android - SDK android-targetSdkVersion <= 28 #121

Closed klich3 closed 3 years ago

klich3 commented 3 years ago

<!--

Have you read the plugins' Code of Conduct? By creating an Issue, you are expected to comply with it, including treating everyone with respect: https://github.com/tripflex/wifiwizard2/blob/master/CODE_OF_CONDUCT.md

-->

Prerequisites

Check all boxes if you have done the following:

Issue type

Select all that apply

Description

On Android this plugin is working with android-targetSdkVersion <= 28. When compile phone gap with Api 29. Currently for upload your app to G-Play is requiered Api version 29 and above.

matteocappello94 commented 3 years ago

Please install it with cordova plugin add https://github.com/tripflex/WifiWizard2 or ionic cordova plugin add https://github.com/tripflex/WifiWizard2 if you are using Ionic framework.

NPM release is older than GitHub master repository and there isn't Android 10 support on it.

klich3 commented 3 years ago

You have one pull request for add new method for support Android 10. See it and, add it if you wanna... Regards

jainsuneet commented 3 years ago

Please install it with cordova plugin add https://github.com/tripflex/WifiWizard2 or ionic cordova plugin add https://github.com/tripflex/WifiWizard2 if you are using Ionic framework.

NPM release is older than GitHub master repository and there isn't Android 10 support on it.

@klich3 @matteocappello94 I am using the current master version and I still get an error 'WiFi not available' on connect()

matteocappello94 commented 3 years ago

Please install it with cordova plugin add https://github.com/tripflex/WifiWizard2 or ionic cordova plugin add https://github.com/tripflex/WifiWizard2 if you are using Ionic framework. NPM release is older than GitHub master repository and there isn't Android 10 support on it.

@klich3 @matteocappello94 I am using the current master version and I still get an error 'WiFi not available' on connect()

Target Android 10, WifiWizard2 can't enable Wifi interface if it's disabled. To use it Wifi interface needs to be on. https://developer.android.com/about/versions/10/privacy/changes#enable-disable-wifi

jainsuneet commented 3 years ago

Please install it with cordova plugin add https://github.com/tripflex/WifiWizard2 or ionic cordova plugin add https://github.com/tripflex/WifiWizard2 if you are using Ionic framework. NPM release is older than GitHub master repository and there isn't Android 10 support on it.

@klich3 @matteocappello94 I am using the current master version and I still get an error 'WiFi not available' on connect()

Target Android 10, WifiWizard2 can't enable Wifi interface if it's disabled. To use it Wifi interface needs to be on. https://developer.android.com/about/versions/10/privacy/changes#enable-disable-wifi

@matteocappello94 The Wifi interface is on. It works without any issue on targetsdk 28 but with 29 it is throwing error 'WiFi not available'. Event location access is also provided.

matteocappello94 commented 3 years ago

@jainsuneet I'm using this version https://github.com/cloudsurfers-it/WifiWizard2/tree/plus (fork of this master with some little improvement for my work) targeting API 29 and Cordova without any problems. Post a snipped of your code please. Are you sure you have updated correctly the plugin? try to remove it with cordova plugin rm wifiwizard2 and re-install it from this repository master or from my "plus" branch.

jainsuneet commented 3 years ago

https://github.com/cloudsurfers-it/WifiWizard2/tree/plus

@matteocappello94 With your version I am getting below error while installing

cordova plugin add https://github.com/cloudsurfers-it/WifiWizard2/tree/plus

Failed to fetch plugin https://github.com/cloudsurfers-it/WifiWizard2/tree/plus via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
CordovaError: Error: npm: Command failed with exit code 1 Error output:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: https://github.com/cloudsurfers-it/WifiWizard2/tree/plus.
npm ERR! package.json npm can't find a package.json file in your current directory.

Here is the snippet of my code to connect to the WiFi

window.WifiWizard2.connect('SSID_Name', true).then((data) => {
    alert(JSON.stringify('success'))
}).catch((error) => {
    alert(JSON.stringify(error))
})
matteocappello94 commented 3 years ago

@jainsuneet when you install from GitHub cordova plugin add https://github.com/cloudsurfers-it/wifiwizard2.git#plus #{branch-name} to select a branch.

jainsuneet commented 3 years ago

cordova plugin add https://github.com/cloudsurfers-it/wifiwizard2.git#plus

@matteocappello94 With your repo is also the same error 'WiFi not available'

matteocappello94 commented 3 years ago

@jainsuneet with Android Studio, you can debug with breakpoints .java class and methods of WifiWizard2 to verify where error occur. Try to pass all args to the connect method, for example: WifiWizard2.connect("NETWORK_NAME", true, "12345678", "WPA", false, true) last argument withPattern it's only present on my "plus" branch. Let you list on Android 10 Wifi connection popup multiple networks, which are selected with RegEx pattern.

matteocappello94 commented 3 years ago

@jainsuneet LOCATION permission is granted, but location interface is enabled?

jainsuneet commented 3 years ago

@jainsuneet LOCATION permission is granted, but location interface is enabled?

@matteocappello94 yes location interface is also enabled and also I cannot pass others args because the wifi is an open network.

matteocappello94 commented 3 years ago

@jainsuneet WIFI_NOT_ENABLED returned from verifyWifiEnabled() method of WifiWizard2.java This method call wifiManager.isWifiEnabled() to check Wifi interface state. You have to debug this method with Android Studio to find your error on your device. If you are using Cordova, open Android project directly with Android Studio.

jainsuneet commented 3 years ago

@jainsuneet WIFI_NOT_ENABLED returned from verifyWifiEnabled() method of WifiWizard2.java This method call wifiManager.isWifiEnabled() to check Wifi interface state. You have to debug this method with Android Studio to find your error on your device. If you are using Cordova, open Android project directly with Android Studio.

@matteocappello94 I am getting 'WiFi not available', I can scan for the wifi ssids and it works but the connection is failing.

The not available is coming from

public void onUnavailable() {
    super.onUnavailable();
    Log.d(TAG, "WiFi not available");
    callbackContext.error("WiFi not available");
}

which is within if(API_VERSION >= 29) block

matteocappello94 commented 3 years ago

@jainsuneet appear popup window when you try to connect? If you can try with a Wifi network with password using method with all args like this: WifiWizard2.connect("NETWORK_NAME", true, "12345678", "WPA", false, true) This works for me without any problems. I've to try to connect to an open network to check if the problem still also present with my app or not.

jainsuneet commented 3 years ago

@jainsuneet appear popup window when you try to connect? If you can try with a Wifi network with password using method with all args like this: WifiWizard2.connect("NETWORK_NAME", true, "12345678", "WPA", false, true) This works for me without any problems. I've to try to connect to an open network to check if the problem still also present with my app or not.

@matteocappello94 Yes now I tried with Password as well. WifiWizard2.connect("NETWORK_NAME", true, "12345678", "WPA", false, true)

Still it throws the same error 'WiFi not available'. Even I am getting the popup with Wifi Network details but after that comes the error.

But if I connect like this WifiWizard2.connect("NETWORK_NAME", true, "12345678", "WPA", false) then it works:

Is there any way that I can connect to an open WiFi? it will be really helpful.

klich3 commented 3 years ago

You can try connect to specify network knowing SSID and Pass. Try new method.

Maybe solve your problem.

https://github.com/klich3/WifiWizard2#dev

jainsuneet commented 3 years ago

You can try connect to specify network knowing SSID and Pass. Try new method.

Maybe solve your problem.

https://github.com/klich3/WifiWizard2#dev

@klich3 So I finally found the issue that why it was not able to connect to an open network. builder.setWpa2Passphrase(newPass); is the standard wpa2 connection. If I disable this line then open network connection works. Other functions like disconnect and remove are not at all working for API >= 29.

klich3 commented 3 years ago

You can try connect to specify network knowing SSID and Pass. Try new method. Maybe solve your problem. https://github.com/klich3/WifiWizard2#dev

@klich3 So I finally found the issue that why it was not able to connect to an open network. builder.setWpa2Passphrase(newPass); is the standard wpa2 connection. If I disable this line then open network connection works. Other functions like disconnect and remove are not at all working for API >= 29.

Thanks, now for default is set as NONE for Open networks. Others Methods are Depricated on >= Api 29

jainsuneet commented 3 years ago

You can try connect to specify network knowing SSID and Pass. Try new method. Maybe solve your problem. https://github.com/klich3/WifiWizard2#dev

@klich3 So I finally found the issue that why it was not able to connect to an open network. builder.setWpa2Passphrase(newPass); is the standard wpa2 connection. If I disable this line then open network connection works. Other functions like disconnect and remove are not at all working for API >= 29.

Thanks, now for default is set as NONE for Open networks. Others Methods are Depricated on >= Api 29

@klich3 With your latest commit on the dev branch I am getting lot of errors and the build is getting failed. Can you please help to resolve the issue.

> Task :app:compileDebugJavaWithJavac FAILED
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2008: error: empty character literal
        if(Algorithm.matches("/WPA3/gim") && PASS != '')
                                                     ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2008: error: unclosed character literal
        if(Algorithm.matches("/WPA3/gim") && PASS != '')
                                                      ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2008: error: ';' expected
        if(Algorithm.matches("/WPA3/gim") && PASS != '')
                                                        ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:1988: error: 'try' without 'catch', 'finally' or resource declarations
      try {
      ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2056: error: 'catch' without 'try'
      } catch (Exception e) {
        ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2060: error: illegal start of type
    }else{
     ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2060: error: ';' expected
    }else{
         ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2061: error: <identifier> expected
      callbackContext.error("SPECIFIER_INVALID_API_VERSION");
                           ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2061: error: illegal start of type
      callbackContext.error("SPECIFIER_INVALID_API_VERSION");
                            ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2062: error: <identifier> expected
      Log.d(TAG, "WifiWizard2: 211 - specifierConnection invalid Android API Version is below as needed.");
           ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2062: error: <identifier> expected
      Log.d(TAG, "WifiWizard2: 211 - specifierConnection invalid Android API Version is below as needed.");
               ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2062: error: illegal start of type
      Log.d(TAG, "WifiWizard2: 211 - specifierConnection invalid Android API Version is below as needed.");
                 ^
App\src-cordova\platforms\android\app\src\main\java\android\wifiwizard2\WifiWizard2.java:2064: error: class, interface, or enum expected
  }
  ^
13 errors