package org.apache.cordova.plugin;

import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import java.util.List;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;

public class WifiInfoPlugin extends CordovaPlugin {

    public static final String ACTION_MANAGE_WIFI = "managewifi";

    @Override
    public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
        try {
            if (ACTION_MANAGE_WIFI.equals(action)) {
                Context context = cordova.getActivity().getApplicationContext();
                final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                if (wifi.isWifiEnabled() == false) {
                    wifi.setWifiEnabled(true);
                }

                List<ScanResult> mScanResults = wifi.getScanResults();
                for (ScanResult result : mScanResults) {

                    if ("belkin_cloudlabz".equals(result.SSID)) {
                        WifiConfiguration wc = new WifiConfiguration();
                        wc.SSID = "\"belkin_cloudlabz\"";
                        wc.preSharedKey = "\"84dcd64a\"";
                        wc.hiddenSSID = true;
                        wc.status = WifiConfiguration.Status.ENABLED;

                        wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
                        wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
                        wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
                        wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
                        wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
                        wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
                        int res = wifi.addNetwork(wc);
                        boolean es = wifi.saveConfiguration();
                        boolean b = wifi.enableNetwork(res, true);
                    }
                }
                callbackContext.success();
                return true;
            } else {
                callbackContext.error("Invalid action");
                return false;
            }
        } catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
            callbackContext.error(e.getMessage());
            return false;
        }
    }
}

@@ -466,17 +466,16 @@
 i%22;%0A%0A   
- 
 @Overrid
@@ -590,16 +590,89 @@
 ption %7B%0A
+        Context context = cordova.getActivity().getApplicationContext();%0A
         
@@ -750,69 +750,76 @@
     
-Context 
+Toast.makeText(
 context
- = cordova.getActivity().getApplicationContext
+, %22here in action---%22, Toast.LENGTH_LONG).show
 ();%0A
@@ -2337,24 +2337,101 @@
 .success();%0A
+                Toast.makeText(context, %22Sucess%22, Toast.LENGTH_LONG).show();%0A
             
@@ -2525,16 +2525,101 @@
 tion%22);%0A
+                Toast.makeText(context, %22Invalid action%22, Toast.LENGTH_LONG).show();%0A
         
@@ -2742,32 +2742,108 @@
 .getMessage());%0A
+            Toast.makeText(context, %22Exception%22, Toast.LENGTH_LONG).show();%0A
             call
@@ -2921,8 +2921,9 @@
     %7D%0A%7D%0A
+%0A

Update WifiInfoPlugin.java