How to create a plugin to take signal strength in phonegap

442 views Asked by At

Okay as the question stated how to create a plug-in to get the signal strength to be honest I have got the signal strength through the native way. So I tried to make changes to the native way. I have no idea what I am doing, I not sure this works, just some friendly pointers on the next step would help especially with the angular.js(something new for me) Oh Can someone mention What is the JSONArray parameter used for in the execute method?

public class App extends Plugin extends CordovaPlugin{

int signalStrength=0;
LocationManager locmanager;
Location c;
TelephonyManager  tm;
getRssi i;
private static final String dbm="getSignalStrength";


@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    // your init code here
    this.tm = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(this.i, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/**
 * Executes the request and returns PluginResult.
 *
 * @param action        The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              A PluginResult object with a status and message.
 */
@Override
public boolean execute(String action, JSONArray args, CallbackContext callBackContext)throws JSONExecption {

        if (action.equals(dbm)) {
            callBackContext.success(Integer.toString(this.getSignalStrength()));
    }
}

public int getSignalStrength() {
    return signalStrength;
}

public class getRssi extends PhoneStateListener
{


    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrengths) {

        super.onSignalStrengthsChanged(signalStrengths);
        int SignalStrength_ASU= signalStrengths.getGsmSignalStrength();
        signalStrength= (2 * SignalStrength_ASU) - 113; // -> dBm

       }
}

}

0

There are 0 answers