我正在学习如何制作cordova插件(以及Java)。我正在研究现有的cordova插件存储库,以了解插件和android意图之间的通信是如何完成的,但是我无法从filechooser plugin
真正了解此代码段中发生了什么PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
this.callback = callbackContext;
callbackContext.sendPluginResult(pluginResult);
上下文是:
public void chooseFile(JSONObject filter, CallbackContext callbackContext) {
String uri_filter = filter.has(MIME) ? filter.optString(MIME) : "*/*";
// type and title should be configurable
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(uri_filter);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
Intent chooser = Intent.createChooser(intent, "Select File");
cordova.startActivityForResult(this, chooser, PICK_FILE_REQUEST);
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
this.callback = callbackContext;
callbackContext.sendPluginResult(pluginResult);
}
更确切地说,我不明白为什么需要创建PluginResult
实例并将其发送到callbackContext.sendPluginResult()
。
如果我删除了PluginResult
和callbackContext.sendPluginResult(pluginResult)
,该插件仍然可以按预期工作:
// PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
// pluginResult.setKeepCallback(true);
this.callback = callbackContext;
// callbackContext.sendPluginResult(pluginResult);
为什么需要该代码?