MacAddress plugin incompatible with Cordova 2.7.0 #120

obgrseneca opened this Issue May 7, 2013 · 1 comment


None yet
2 participants

The title says it, the MacAddress plugin seems to be incompatible with newer cordova release.
The first error I am getting is, that "org.apache.cordova.api.Plugin" does not exist. The rest are errors dependant on this one.

@obgrseneca, here's a fixed version of the Java plugin for cordova 2.7, I'm not sure what the JS plugin should look like I ended up just calling cordova.exec directly. The new plugin API doesn't seem to support synchronous calls anymore so it's async now:

package com.phonegap.plugin.macaddress;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

 * The Class MacAddressPlugin.
public class MacAddressPlugin extends CordovaPlugin {

    /* (non-Javadoc)
     * @see org.apache.cordova.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {

        if (action.equals("getMacAddress")) {
            String macAddress = this.getMacAddress();
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, macAddress);
            return true;

        return false;

     * Gets the mac address.
     * @return the mac address
    private String getMacAddress() {
        String macAddress = null;
        WifiManager wm = (WifiManager) cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
        macAddress = wm.getConnectionInfo().getMacAddress();

        if (macAddress == null || macAddress.length() == 0) {
            macAddress = "00:00:00:00:00:00";

        return macAddress;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment