Я учусь делать плагины Cordova (и хорошо Java).Я смотрю на существующие репозитории плагинов Cordova, чтобы увидеть, как осуществляется связь между плагином и намерениями Android, но я не могу понять, что происходит в этом фрагменте из плагина filechooser
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);
Зачем нужен этот код?