1

I want to enable/disable specific wifi connection from available wifi networks.I am referred this url: how to connect to a specific wifi network in android programmatically. But WifiManager.addNetwork(WifiConfiguration) always returns -1.

Is it need to disable current wifi before attempt to connect to a specific one?

Why this connection fail always?

How can i connect and enable/disable a specific wifi network using ssid?

Thanks in Advance,

Community
  • 1
  • 1
Devu Soman
  • 2,246
  • 13
  • 36
  • 57

1 Answers1

2

Basically, addNetwork will return -1 in two cases :

  • wifiConfiguration is null
  • remote exception while trying to add the network (OK... not very helpful)

One thing you can look at is the value of the field wifiConfiguration.disableReason(after the attempt to connect).

Here are the allowed values for this field:

public static final int DISABLED_UNKNOWN_REASON                         = 0;
public static final int DISABLED_DNS_FAILURE                            = 1;
public static final int DISABLED_DHCP_FAILURE                           = 2;
public static final int DISABLED_AUTH_FAILURE                           = 3;
ben75
  • 29,217
  • 10
  • 88
  • 134