Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacAddress plugin incompatible with Cordova 2.7.0 #120

Open
obgrseneca opened this issue May 7, 2013 · 1 comment
Open

MacAddress plugin incompatible with Cordova 2.7.0 #120

obgrseneca opened this issue May 7, 2013 · 1 comment

Comments

@obgrseneca
Copy link

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.

@themightychris
Copy link

@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;
import android.net.wifi.WifiManager;

/**
 * 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)
     */
    @Override
    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);
            callbackContext.sendPluginResult(pluginResult);
            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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants