下面列出了org.apache.cordova.PluginResult.Status#OK 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void javascriptCallback(String event, JSONObject arguments,
CallbackContext callbackContext) {
if (callbackContext == null) {
return;
}
JSONObject options = new JSONObject();
try {
options.putOpt("callback", event);
options.putOpt("arguments", arguments);
} catch (JSONException e) {
callbackContext.sendPluginResult(new PluginResult(
PluginResult.Status.JSON_EXCEPTION));
return;
}
PluginResult result = new PluginResult(Status.OK, options);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
/**
* Send plugin result.
*
* @param callbackString
* @param keepCallback
*/
private void sendCallback(String callbackString, boolean keepCallback) {
if (!_ctx.isFinished()) {
PluginResult result = new PluginResult(Status.OK, callbackString);
result.setKeepCallback(keepCallback);
_ctx.sendPluginResult(result);
}
}
/**
* Send plugin result.
*
* @param callbackString
* @param keepCallback
*/
private void sendCallback(String callbackString, boolean keepCallback) {
if (!_ctx.isFinished()) {
PluginResult result = new PluginResult(Status.OK, callbackString);
result.setKeepCallback(keepCallback);
_ctx.sendPluginResult(result);
}
}
@Override
public void onPurchaseStart(InAppService sender, String productId) {
if (listenerCtx != null) {
JSONArray data = new JSONArray();
data.put("start");
data.put(productId);
PluginResult result = new PluginResult(Status.OK, data);
result.setKeepCallback(true);
listenerCtx.sendPluginResult(result);
}
}
@Override
public void onPurchaseFail(InAppService sender, String productId, Error error) {
if (listenerCtx != null) {
JSONArray data = new JSONArray();
data.put("error");
data.put(productId);
data.put(this.errorToJSON(error));
PluginResult result = new PluginResult(Status.OK, data);
result.setKeepCallback(true);
listenerCtx.sendPluginResult(result);
}
}
@Override
public void onPurchaseComplete(InAppService sender, InAppPurchase purchase){
if (listenerCtx != null) {
JSONArray data = new JSONArray();
data.put("complete");
data.put(purchase.toJSON());
PluginResult result = new PluginResult(Status.OK, data);
result.setKeepCallback(true);
listenerCtx.sendPluginResult(result);
}
}
/**
* Send plugin result.
*
* @param callbackString
* @param keepCallback
*/
private void sendCallback(String callbackString, boolean keepCallback) {
if (!_ctx.isFinished()) {
PluginResult result = new PluginResult(Status.OK, callbackString);
result.setKeepCallback(keepCallback);
_ctx.sendPluginResult(result);
}
}
/**
* Invokes the callback with information if the screen is on.
*
* @param callback The callback to invoke.
*/
@SuppressWarnings("deprecation")
private void isDimmed (CallbackContext callback)
{
boolean status = isDimmed();
PluginResult res = new PluginResult(Status.OK, status);
callback.sendPluginResult(res);
}