Skip to content

Commit eb4ef3a

Browse files
committed
upgrade to cordove 2.2.0
1 parent 8f3f1d7 commit eb4ef3a

File tree

5 files changed

+111
-17
lines changed

5 files changed

+111
-17
lines changed

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ PhoneGap WifiInfoPlugin
33

44
* Author: HondaDai
55
* License - The MIT License
6-
* Test on PhoneGap 1.7.0 (cordova 1.7)
6+
* Test on cordova 2.2.0 (PhoneGap 2.2.0)
77

88

99
Install Step (On Eclipse)
1010
--------------------------
1111

1212
1. Import File System to folder **src**, select **WifiInfoPlugin.java**
13-
2. Edit **res\xml\plugins.xml**, add `<plugin name="WifiInfoPlugin" value="com.phonegap.plugin.WifiInfoPlugin"/>` into `<plugins> </plugins>`
13+
2. Edit **res\xml\config.xml**, add `<plugin name="WifiInfoPlugin" value="org.apache.cordova.plugin.WifiInfoPlugin"/>` into `<plugins> </plugins>`
1414
3. add `<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>` into **AndroidManifest.xml**
1515
4. Import **WifiInfoPlugin.js** into .html
1616

WifiInfoPlugin.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
package com.phonegap.plugin;
1+
package org.apache.cordova.plugin;
22

3-
import org.apache.cordova.api.PluginResult;
4-
import org.apache.cordova.api.PluginResult.Status;
3+
4+
import org.apache.cordova.api.CallbackContext;
5+
import org.apache.cordova.api.CordovaPlugin;
56
import org.json.JSONArray;
67
import org.json.JSONException;
78
import org.json.JSONObject;
89

9-
import com.phonegap.api.Plugin;
1010

1111
import android.content.Context;
1212
import android.net.wifi.WifiInfo;
1313
import android.net.wifi.WifiManager;
1414

15-
public class WifiInfoPlugin extends Plugin {
15+
public class WifiInfoPlugin extends CordovaPlugin {
1616

1717
@Override
18-
public PluginResult execute(String action, JSONArray data, String callback) {
18+
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
1919

20-
Context context = ctx.getApplicationContext();
20+
Context context = cordova.getActivity().getApplicationContext();
2121
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
2222
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
2323

@@ -33,15 +33,10 @@ public PluginResult execute(String action, JSONArray data, String callback) {
3333
obj.put("LinkSpeed", wifiInfo.getLinkSpeed());
3434

3535
} catch (JSONException e) {
36-
3736
e.printStackTrace();
38-
return new PluginResult(Status.JSON_EXCEPTION);
37+
callbackContext.error("JSON Exception");
3938
}
40-
41-
return new PluginResult(Status.OK, obj);
42-
43-
44-
39+
callbackContext.success(obj);
40+
return true;
4541
}
46-
4742
}

old version/PhoneGap 1.7/Readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
PhoneGap WifiInfoPlugin
2+
==============
3+
4+
* Author: HondaDai
5+
* License - The MIT License
6+
* Test on PhoneGap 1.7.0 (cordova 1.7)
7+
8+
9+
Install Step (On Eclipse)
10+
--------------------------
11+
12+
1. Import File System to folder **src**, select **WifiInfoPlugin.java**
13+
2. Edit **res\xml\plugins.xml**, add `<plugin name="WifiInfoPlugin" value="com.phonegap.plugin.WifiInfoPlugin"/>` into `<plugins> </plugins>`
14+
3. add `<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>` into **AndroidManifest.xml**
15+
4. Import **WifiInfoPlugin.js** into .html
16+
17+
API
18+
-----
19+
20+
### Example 1
21+
window.plugins.WifiInfo.get(function(wifi){ console.log(wifi); });
22+
> undefined
23+
> Object
24+
BSSID: "00:21:91:08:63:19"
25+
HiddenSSID: false
26+
IpAddress: -1191139136
27+
LinkSpeed: 65
28+
MacAddress: "E0:B9:A5:8B:6E:95"
29+
NetworkId: 0
30+
RSSI: -55
31+
SSID: "dlink"
32+
__proto__: Object
33+
34+
### Example 2
35+
window.plugins.WifiInfo.get(function(wifi){
36+
alert(wifi.SSID);
37+
});
38+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.phonegap.plugin;
2+
3+
import org.apache.cordova.api.PluginResult;
4+
import org.apache.cordova.api.PluginResult.Status;
5+
import org.json.JSONArray;
6+
import org.json.JSONException;
7+
import org.json.JSONObject;
8+
9+
import com.phonegap.api.Plugin;
10+
11+
import android.content.Context;
12+
import android.net.wifi.WifiInfo;
13+
import android.net.wifi.WifiManager;
14+
15+
public class WifiInfoPlugin extends Plugin {
16+
17+
@Override
18+
public PluginResult execute(String action, JSONArray data, String callback) {
19+
20+
Context context = ctx.getApplicationContext();
21+
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
22+
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
23+
24+
JSONObject obj = new JSONObject();
25+
try {
26+
obj.put("BSSID", wifiInfo.getBSSID());
27+
obj.put("HiddenSSID", wifiInfo.getHiddenSSID());
28+
obj.put("SSID", wifiInfo.getSSID());
29+
obj.put("MacAddress", wifiInfo.getMacAddress());
30+
obj.put("IpAddress", wifiInfo.getIpAddress());
31+
obj.put("NetworkId", wifiInfo.getNetworkId());
32+
obj.put("RSSI", wifiInfo.getRssi());
33+
obj.put("LinkSpeed", wifiInfo.getLinkSpeed());
34+
35+
} catch (JSONException e) {
36+
37+
e.printStackTrace();
38+
return new PluginResult(Status.JSON_EXCEPTION);
39+
}
40+
41+
return new PluginResult(Status.OK, obj);
42+
43+
44+
45+
}
46+
47+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var WifiInfo= function() {
2+
};
3+
4+
WifiInfo.prototype.get = function(success, fail) {
5+
PhoneGap.exec(success, success, 'WifiInfoPlugin', null, [] );
6+
};
7+
8+
cordova.addConstructor(function() {
9+
10+
if (!window.plugins) {
11+
window.plugins = {};
12+
}
13+
window.plugins.WifiInfo = new WifiInfo();
14+
});

0 commit comments

Comments
 (0)