Skip to content

Commit

Permalink
New plugin version
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed Jan 5, 2016
1 parent 927ed35 commit a22b200
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ hs_err_pid*
.idea/*
.project
.settings/*

*.log
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,57 @@ cordova.plugins.hotspot.isWifiDirectSupported(
);
```


### Create Hotspot

```javascript
cordova.plugins.hotspot.createHotspot(ssid, mode, password,
function () {
// Hotspot is created
},function () {
// Error
}
);
```

### Stop Hotspot

```javascript
cordova.plugins.hotspot.stopHotspot(
function () {
// Hotspot is disabled
},function () {
// Error
}
);
```

### Check if Hotspot is enabled

```javascript
cordova.plugins.hotspot.isHotspotEnabled(
function () {
// Hotspot is on
},function () {
// Hotspot is off
}
);
```

### Get all connected devices

```javascript
cordova.plugins.hotspot.getAllHotspotDevices(
function (devices) {
// array of JSON objects:
// -> ip
// -> mac
},function () {
// error
}
);
```

### Check if Wifi is enabled

```javascript
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-hotspot",
"version": "0.1.0",
"version": "0.2.0",
"description": "Cordova WiFi Hotspot Plugin",
"cordova": {
"id": "cordova-plugin-hotspot",
Expand Down
6 changes: 5 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SOFTWARE.

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-hotspot"
version="0.1.0">
version="0.2.0">

<name>Cordova HotSpot Plugin</name>

Expand Down Expand Up @@ -58,9 +58,13 @@ SOFTWARE.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_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.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
</config-file>
<config-file target="AndroidManifest.xml" parent="application/activity">
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</config-file>

<source-file src="src/android/de/martinreinhardt/cordova/plugins/hotspot/HotSpotPlugin.java"
target-dir="src/de/martinreinhardt/cordova/plugins/hotspot"/>
Expand Down
66 changes: 33 additions & 33 deletions src/android/com/mady/wifi/api/WifiHotSpots.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

Expand All @@ -23,8 +24,12 @@
import java.util.List;
import java.util.Timer;


public class WifiHotSpots {
/**
* Logging Tag
*/
private static final String LOG_TAG = "WifiHotSpots";

public static boolean isConnectToHotSpotRunning = false;
WifiManager mWifiManager;
WifiInfo mWifiInfo;
Expand Down Expand Up @@ -67,8 +72,8 @@ private static boolean runAsRoot(final String command) {

return (retval == 0);

} catch (Exception e) {

} catch (Exception ex) {
Log.e(LOG_TAG, "Unkown error during running as root.", ex);
return false;

}
Expand Down Expand Up @@ -334,6 +339,7 @@ public boolean startHotSpot(boolean enable) {
mMethod.invoke(mWifiManager, null, enable);
return true;
} catch (Exception ex) {
Log.e(LOG_TAG, "Unkown error during hotspot creation.", ex);
}
break;
}
Expand All @@ -359,6 +365,7 @@ public boolean setAndStartHotSpot(boolean enable, String SSID) {
try {
mMethod.invoke(mWifiManager, netConfig, true);
} catch (Exception e) {
Log.e(LOG_TAG, "Unkown error during setting hotspot.", e);
return false;
}
startHotSpot(enable);
Expand All @@ -372,26 +379,27 @@ public boolean setAndStartHotSpot(boolean enable, String SSID) {
* Method to Change SSID and Password of Device Access Point
*
* @param SSID a new SSID of your Access Point
* @param mode wireless mode
* @param passWord a new password you want for your Access Point
*/
public boolean setHotSpot(String SSID, String passWord) {
public boolean setHotSpot(String SSID, String mode, String passWord) {
/*
* Before setting the HotSpot with specific Id delete the default AP Name.
*/
/*
List<WifiConfiguration> list = mWifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals(SSID)) {
//wm.disconnect();
//wm.enableNetwork(i.networkId, true);
//wm.reconnect();
//mWifiManager.disableNetwork(i.networkId);
mWifiManager.removeNetwork(i.networkId);
mWifiManager.saveConfiguration();
break;
}
}
*/
/*
List<WifiConfiguration> list = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals(SSID)) {
//wm.disconnect();
//wm.enableNetwork(i.networkId, true);
//wm.reconnect();
//mWifiManager.disableNetwork(i.networkId);
mWifiManager.removeNetwork(i.networkId);
mWifiManager.saveConfiguration();
break;
}
}*/

//mWifiManager.acquire();
Method[] mMethods = mWifiManager.getClass().getDeclaredMethods();

Expand Down Expand Up @@ -424,7 +432,7 @@ public boolean setHotSpot(String SSID, String passWord) {
return true;

} catch (Exception e) {

Log.e(LOG_TAG, "Unkown error during saving wifi config.", e);
}
}
}
Expand All @@ -439,7 +447,7 @@ public boolean isWifiApEnabled() {
Method method = mWifiManager.getClass().getMethod("isWifiApEnabled");
return (Boolean) method.invoke(mWifiManager);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, "Unkown error during checking ap wifi.", e);
}

return false;
Expand All @@ -448,7 +456,7 @@ public boolean isWifiApEnabled() {
/**
* shred all Configured wifi Networks
*/
public boolean shredAllWifi() {
public boolean sharedAllWifi() {
Context context = mContext;
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

Expand Down Expand Up @@ -486,28 +494,21 @@ public ArrayList<WifiConfiguration> getProfiles() {
* @param netType Network Security Type OPEN PSK EAP OR WEP
*/
public void addWifiNetwork(String netSSID, String netPass, String netType) {

WifiConfiguration wifiConf = new WifiConfiguration();
if (netType.equalsIgnoreCase("OPEN")) {

wifiConf.SSID = "\"" + netSSID + "\"";
wifiConf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
mWifiManager.addNetwork(wifiConf);
mWifiManager.saveConfiguration();

} else if (netType.equalsIgnoreCase("WEP")) {

wifiConf.SSID = "\"" + netSSID + "\"";
wifiConf.wepKeys[0] = "\"" + netPass + "\"";
wifiConf.wepTxKeyIndex = 0;
wifiConf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifiConf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
mWifiManager.addNetwork(wifiConf);
mWifiManager.saveConfiguration();


} else {

wifiConf.SSID = "\"" + netSSID + "\"";
wifiConf.preSharedKey = "\"" + netPass + "\"";
wifiConf.hiddenSSID = true;
Expand All @@ -521,11 +522,7 @@ public void addWifiNetwork(String netSSID, String netPass, String netType) {
wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
mWifiManager.addNetwork(wifiConf);
mWifiManager.saveConfiguration();


}


}

/**
Expand Down Expand Up @@ -609,6 +606,7 @@ public String getWifiPassword(String SSID) {
}
bufRead.close();
} catch (Exception e) {
Log.e(LOG_TAG, "Interrupt error during get password.", e);
Toast.makeText(mContext, "error read wpa_supplicant.conf file", Toast.LENGTH_LONG)
.show();
return null;
Expand Down Expand Up @@ -638,9 +636,11 @@ public void CheckRoot() {
this.gotRoot = false;
}
} catch (InterruptedException e) {
Log.e(LOG_TAG, "Interrupt error during check root.", e);
this.gotRoot = false;
}
} catch (IOException e) {
} catch (IOException ex) {
Log.e(LOG_TAG, "Unkown IO error during check root", ex);
this.gotRoot = false;
}
}
Expand Down
Loading

0 comments on commit a22b200

Please sign in to comment.