falconeta / capacitor-wifi-connect

13 stars 4 forks source link

Connecting Capacitor (Android) to Wi-Fi Network getting no results #24

Open jguilhermesl opened 3 weeks ago

jguilhermesl commented 3 weeks ago

Description: I am experiencing an issue when trying to use the library to connect Capacitor (Android) to a Wi-Fi network. I followed the documentation step-by-step, but I am encountering difficulties at the connection stage.

Steps to Reproduce:

  1. Followed the installation and configuration guide for the library as described in the official documentation.

    • I created a utility to first try to connect without the password, if it doesn't work, try connecting with the password.
      
      export const wifiConnect = async ({ ssid, password }) => {
      try {
      const data = await CapacitorWifiConnect.connect({
      ssid,
      saveNetwork: true,
      });
      if (data.value === 0) {
      return data;
      }
      } catch (_) {
      const data = await CapacitorWifiConnect.secureConnect({
      ssid,
      password,
      saveNetwork: true,
      });
      if (data.value === 0) {
      return data;
      }
      }

    return { status: -1 }; };

  2. When attempting to connect to a Wi-Fi network, a modal is displayed correctly asking for the connection. Screenshot 2024-07-01 at 10 41 37
  3. When clicking "Connect," the device seemingly does not accept/recognize the connection.
  4. The device remains disconnected from any network.

Expected Behavior: The device should successfully connect to the specified Wi-Fi network when "Connect" is clicked.

Actual Behavior: The device remains unconnected. Screenshot 2024-07-01 at 10 45 42

jguilhermesl commented 2 weeks ago

@falconeta can you help me?

falconeta commented 2 weeks ago

Hi @jguilhermesl, what android version is used? Do you added the correct permissions inside the manifest? This is a strange issue... any error on logcat?

jguilhermesl commented 2 weeks ago

Hey @falconeta, yes. This is my android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:networkSecurityConfig="@xml/network_security_config">

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>

    <!-- Permissions -->

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

I'm using these versions:

inSdkVersion = 22
compileSdkVersion = 34
targetSdkVersion = 34
jguilhermesl commented 2 weeks ago

I'm not receiving errors at logs @falconeta

jguilhermesl commented 2 weeks ago

Hey @falconeta, any ideas?

falconeta commented 2 weeks ago

Can you share: Device model Android version Native log session

With this info maybe I can reproduce your situation

jguilhermesl commented 2 weeks ago

@falconeta I'm using Android Studio to emulate.

The device is 10.1 WXGA (Tablet) API 33 (emulator) (10.1_WXGA_Tablet_API_33) The android version is 13

What is the native log session?

falconeta commented 2 weeks ago

https://developer.android.com/studio/debug/logcat

falconeta commented 2 weeks ago

@jguilhermesl I will try on an emulator, but this plugin works best when tested on a real device. The emulator inherits the wifi state from the PC and changing the SSID is equivalent to changing the SSID on the PC.

Do a test on a real device ;)