Example usage for org.apache.cordova PluginResult PluginResult

List of usage examples for org.apache.cordova PluginResult PluginResult

Introduction

In this page you can find the example usage for org.apache.cordova PluginResult PluginResult.

Prototype

public PluginResult(Status status, List<PluginResult> multipartMessages) 

Source Link

Usage

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ???//from  w  ww .  j a  va2s . c o m
 *
 * @return PluginResult
 */
private PluginResult listBoundBluetooth() {
    Set<BluetoothDevice> pairedDevices = mBtadapter.getBondedDevices();
    JSONArray devicesBound = new JSONArray();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            if ((device.getName() != null) && (device.getBluetoothClass() != null)) {
                JSONObject boundDevice = new JSONObject();
                try {
                    boundDevice.put(DEVICE_NAME, device.getName());
                    boundDevice.put(DEVICE_MACADDRESSG, device.getAddress());
                    devicesBound.put(boundDevice);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

    }
    return new PluginResult(PluginResult.Status.OK, devicesBound);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ?mac?????//from w  w w. ja  va 2 s .  co m
 *
 * @param args
 *            ????mac?json
 * @return PluginResult
 */
private PluginResult unpairBluetooth(JSONArray args) {
    String addressDevice = null;
    try {
        addressDevice = args.getString(0);
    } catch (JSONException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    }

    if (mBtadapter.isDiscovering()) {
        mBtadapter.cancelDiscovery();
    }
    BluetoothDevice device = mBtadapter.getRemoteDevice(addressDevice);
    boolean IsUnpaired = false;
    Method m;
    try {
        m = device.getClass().getMethod("removeBond");
        IsUnpaired = (Boolean) m.invoke(device);
    } catch (SecurityException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    }
    return new PluginResult(PluginResult.Status.OK, IsUnpaired);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ?mac???//from w  ww .ja v a  2  s  .  c o  m
 *
 * @param args
 *            ???mac?json
 * @return PluginResult
 */
private PluginResult pairBluetooth(JSONArray args) {
    String addressDevice = null;
    try {
        addressDevice = args.getString(0);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    if (mBtadapter.isDiscovering()) {
        mBtadapter.cancelDiscovery();
    }

    BluetoothDevice device = mBtadapter.getRemoteDevice(addressDevice);
    boolean paired = false;
    Method m;
    try {
        m = device.getClass().getMethod("createBond");
        paired = (Boolean) m.invoke(device);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    return new PluginResult(PluginResult.Status.OK, paired);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ?// www.  j  a va  2  s .  c om
 *
 * @return PluginResult
 */
private PluginResult disableBluetooth() {
    boolean isDisabled = false;
    if (mBtadapter.isEnabled()) {
        isDisabled = mBtadapter.disable();
    } else {
        isDisabled = true;
    }
    return new PluginResult(PluginResult.Status.OK, isDisabled);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ?/*from w w w.ja  va  2s . com*/
 *
 * @return
 */
private PluginResult enableBluetooth() {
    boolean enabled = false;
    if (mBtadapter.isEnabled()) {
        enabled = true;
    } else {
        enabled = mBtadapter.enable();
    }
    return new PluginResult(PluginResult.Status.OK, enabled);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ??//from  ww w .j  av a 2s. com
 *
 * @return PluginResult
 */
private PluginResult isBluetoothEnabled() {
    PluginResult result;
    boolean isEnabled = mBtadapter.isEnabled();
    result = new PluginResult(PluginResult.Status.OK, isEnabled);
    return result;
}

From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java

License:Open Source License

/**
 * ???/*from w w w .j  a  va2s .  co  m*/
 *
 * @param status
 *            ???
 * */
private void resolveSMSSendResult(SMS_RESULT_STATUS status) {
    PluginResult.Status callbackStatus = PluginResult.Status.OK;
    if (status != SMS_RESULT_STATUS.SEND_SUCCESS) {
        callbackStatus = PluginResult.Status.ERROR;
    }
    PluginResult result = new PluginResult(callbackStatus, status.ordinal());
    result.setKeepCallback(false);
    mCallbackContext.sendPluginResult(result);
}

From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {//from   ww  w. j av a2 s . c  o  m
        if (action.equals(COMMAND_DELETE_ALL_CALL_RECORDS)) {
            boolean deleteSuccess = deleteAllCallRecords(args.getString(0));
            PluginResult result = new PluginResult(PluginResult.Status.OK, deleteSuccess);
            callbackContext.sendPluginResult(result);
        } else if (action.equals(COMMAND_DELETE_CALL_RECORD)) {
            boolean deleteSuccess = deleteCallRecord(args.getString(0), args.getLong(1));
            PluginResult result = new PluginResult(PluginResult.Status.OK, deleteSuccess);
            callbackContext.sendPluginResult(result);
        } else if (action.equals(COMMAND_FIND_CALL_RECORDS)) {
            JSONArray array = findCallRecords(args.getJSONObject(0), args.getInt(1), args.getInt(2));
            callbackContext.success(array);
        } else if (action.equals(COMMAND_GET_CALL_RECORD)) {
            JSONObject object = getCallRecord(args.getString(0), args.getInt(1));
            callbackContext.success(object);
        } else if (action.equals(COMMAND_GET_CALL_RECORD_COUNT)) {
            int count = getCallRecordCount(args.getString(0));
            callbackContext.success(count);
        } else if (action.equals(COMMAND_INITIATE_VOICE_CALL)) {
            boolean isCallSuccess = false;
            boolean mobileNetAccessible = isSimCardAvailable(mContext);
            isCallSuccess = initiateVoiceCall(args.getString(0));
            if (!mobileNetAccessible || !isCallSuccess) {
                PluginResult result = new PluginResult(PluginResult.Status.ERROR);
                callbackContext.sendPluginResult(result);
            }
            callbackContext.success();
        }
    } catch (JSONException e) {
        callbackContext.error(e.toString());
    }
    return true;
}

From source file:com.projectoxford.cordova.speechrecognition.OxfordSpeechRecognition.java

License:Open Source License

public void onPartialResponseReceived(final String response) {
    Log.d("OxfordSpeechRecognition", "partial");

    JSONObject event = new JSONObject();
    try {//from  ww w . j  a  va2s .co  m
        event.put("partial", response);
    } catch (JSONException e) {
        // this will never happen
    }
    PluginResult pr = new PluginResult(PluginResult.Status.OK, event);
    pr.setKeepCallback(true);
    speechRecognizerCallbackContext.sendPluginResult(pr);
}

From source file:com.projectoxford.cordova.speechrecognition.OxfordSpeechRecognition.java

License:Open Source License

public void onFinalResponseReceived(final RecognitionResult response) {
    Log.d("OxfordSpeechRecognition", "final");
    boolean isFinalDicationMessage = m_recoMode == SpeechRecognitionMode.LongDictation
            && (response.RecognitionStatus == RecognitionStatus.EndOfDictation
                    || response.RecognitionStatus == RecognitionStatus.DictationEndSilenceTimeout);
    if ((m_recoMode == SpeechRecognitionMode.ShortPhrase) || isFinalDicationMessage) {
        // we got the final result, so it we can end the mic reco.  No need to do this
        // for dataReco, since we already called endAudio() on it as soon as we were done
        // sending all the data.
        m_micClient.endMicAndRecognition();
    }/*from  w ww . j  a v a2 s  .  c o  m*/

    if ((m_recoMode == SpeechRecognitionMode.ShortPhrase) || isFinalDicationMessage) {
        //speechRecognizerCallbackContext.sendPluginResult(pr); 
    }

    JSONObject event = new JSONObject();
    String result = "";
    if (!isFinalDicationMessage && response.Results.length > 0) {
        //for (int i = 0; i < response.Results.length; i++) {
        //response.Results[i].DisplayText;
        //}
        result = response.Results[0].DisplayText;
    }
    try {
        event.put("result", result);
    } catch (JSONException e) {
        // this will never happen
    }
    PluginResult pr = new PluginResult(PluginResult.Status.OK, event);
    pr.setKeepCallback(true);
    speechRecognizerCallbackContext.sendPluginResult(pr);
}