1

I want to enable the user to connect to WiFi networks through my app, the connecting goes properly when the user manages to enter the correct WiFi password, but when he enters a wrong WiFi password, Two unwelcomed issues appear:

  1. The app receives that it's now connected to that WiFi Network although the connection doesn't completed successfully due to wrong password.
  2. making it thinks that the connection happened, leading it to disconnect from the already successfully connected network, and then the user loses WiFi connection.

I'm detecting the WiFi connections changing using a BroadcastReceiver with the following manifest description:

    <receiver android:name="com.automation.standards.WifiReceiver">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
    </receiver>

And dealing with the changes the following way :

WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

if(wifiMgr.isWifiEnabled()){
        Toast.makeText(mContext, "wifi is enabled", Toast.LENGTH_LONG).show();
  }

WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String connected_net = (wifiInfo.getSSID()).toString(); // Here I'm getting the failed-in-connection WiFi Net

and about how to connect to a WiFi network when the user presses connect and enters a password:

final WifiManager wifiManager = (WifiManager)(mContext).getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf); // Adding the Network Configuration to the WifiManager
wifiManager.disconnect();
wifiManager.enableNetwork(conf.networkId, true);
wifiManager.reconnect();
wifiManager.saveConfiguration();
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
  • 1
    Try using NetworkInfo class, with isConnected() method. Reference link, http://stackoverflow.com/questions/3841317/how-to-see-if-wifi-is-connected-in-android – Chitrang Oct 15 '14 at 12:32

0 Answers0