forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMacAddressPlugin.java
More file actions
69 lines (54 loc) · 1.81 KB
/
MacAddressPlugin.java
File metadata and controls
69 lines (54 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.phonegap.plugin.macaddress;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.net.wifi.WifiManager;
/**
* The Class MacAddressPlugin.
*/
public class MacAddressPlugin extends Plugin {
@Override
public boolean isSynch(String action) {
if (action.equals("getMacAddress")) {
return true;
}
return false;
}
/* (non-Javadoc)
* @see org.apache.cordova.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
*/
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult result = null;
if (action.equals("getMacAddress")) {
String macAddress = this.getMacAddress();
if (macAddress != null) {
JSONObject JSONresult = new JSONObject();
try {
JSONresult.put("mac", macAddress);
result = new PluginResult(PluginResult.Status.OK, JSONresult);
} catch (JSONException jsonEx) {
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
}
return result;
}
/**
* Gets the mac address.
*
* @return the mac address
*/
private String getMacAddress() {
String macAddress = null;
WifiManager wm = (WifiManager) this.ctx.getSystemService(Context.WIFI_SERVICE);
macAddress = wm.getConnectionInfo().getMacAddress();
if (macAddress == null || macAddress.length() == 0) {
macAddress = "00:00:00:00:00:00";
}
return macAddress;
}
}