下面列出了org.apache.cordova.CordovaArgs#getString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean execIsFirstRun(CordovaArgs args, CallbackContext callbackContext) {
try {
boolean isFirstRun = false;
String packageHash = args.getString(0);
CodePushPackageMetadata currentPackageMetadata = codePushPackageManager.getCurrentPackageMetadata();
if (null != currentPackageMetadata) {
/* This is the first run for a package if we just updated, and the current package hash matches the one provided. */
isFirstRun = (null != packageHash
&& !packageHash.isEmpty()
&& packageHash.equals(currentPackageMetadata.packageHash)
&& didUpdate);
}
callbackContext.success(isFirstRun ? 1 : 0);
} catch (JSONException e) {
callbackContext.error("Invalid package hash. " + e.getMessage());
}
return true;
}
private boolean execPreInstall(CordovaArgs args, CallbackContext callbackContext) {
/* check if package is valid */
try {
final String startLocation = args.getString(0);
File startPage = this.getStartPageForPackage(startLocation);
if (startPage != null) {
/* start page exists */
callbackContext.success();
} else {
callbackContext.error("Could not get the package start page");
}
} catch (Exception e) {
callbackContext.error("Could not get the package start page");
}
return true;
}
private void sendData(final CordovaArgs args,
final CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "sendData");
String connectionId = args.getString(0);
String data = args.getString(1);
try {
if (api != null) {
api.sendData(connectionId, data);
callbackContext.success();
} else {
callbackContext.error("Service not present");
}
} catch (RemoteException e) {
callbackContext.error(e.getMessage());
}
}
private boolean execIsFailedUpdate(CordovaArgs args, CallbackContext callbackContext) {
try {
final String packageHash = args.getString(0);
boolean isFailedUpdate = this.codePushPackageManager.isFailedUpdate(packageHash);
callbackContext.success(isFailedUpdate ? 1 : 0);
} catch (JSONException e) {
callbackContext.error("Could not read the package hash: " + e.getMessage());
}
return true;
}
private boolean execInstall(CordovaArgs args, CallbackContext callbackContext) {
try {
final String startLocation = args.getString(0);
final InstallMode installMode = InstallMode.fromValue(args.optInt(1));
final int minimumBackgroundDuration = args.optInt(2);
File startPage = this.getStartPageForPackage(startLocation);
if (startPage != null) {
/* start page file exists */
/* navigate to the start page */
if (InstallMode.IMMEDIATE.equals(installMode)) {
this.navigateToFile(startPage);
markUpdate();
} else {
InstallOptions pendingInstall = new InstallOptions(installMode, minimumBackgroundDuration);
this.codePushPackageManager.savePendingInstall(pendingInstall);
}
callbackContext.success();
} else {
callbackContext.error("Could not find the package start page.");
}
} catch (Exception e) {
callbackContext.error("Cound not read webview URL: " + e.getMessage());
}
return true;
}
private void onDataReceived(final CordovaArgs args,
final CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "onDataReceived");
String connectionId = args.getString(0);
WearConnection connection = connections.get(connectionId);
if (connection != null) {
connection.addDataListener(callbackContext);
} else {
callbackContext.error("Invalid connection handle");
}
}
private void onError(final CordovaArgs args,
final CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "onError");
String connectionId = args.getString(0);
WearConnection connection = connections.get(connectionId);
if (connection != null) {
connection.addErrorListener(callbackContext);
} else {
callbackContext.error("Invalid connection handle");
}
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArray 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.
*/
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
if (action.equals("play")) {
this.callbackContext = callbackContext;
CordovaResourceApi resourceApi = webView.getResourceApi();
String target = args.getString(0);
final JSONObject options = args.getJSONObject(1);
String fileUriStr;
try {
Uri targetUri = resourceApi.remapUri(Uri.parse(target));
fileUriStr = targetUri.toString();
} catch (IllegalArgumentException e) {
fileUriStr = target;
}
Log.v(LOG_TAG, fileUriStr);
final String path = stripFileProtocol(fileUriStr);
// Create dialog in new thread
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
openVideoDialog(path, options);
}
});
// Don't return any result now
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
callbackContext = null;
return true;
}
else if (action.equals("close")) {
if (dialog != null) {
if(player.isPlaying()) {
player.stop();
}
player.release();
dialog.dismiss();
}
if (callbackContext != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK);
result.setKeepCallback(false); // release status callback in JS side
callbackContext.sendPluginResult(result);
callbackContext = null;
}
return true;
}
return false;
}