Source:
<code>public void setDataForFields(Bundle bundle) throws JavaRosaException { FormController formController = Collect.getInstance().getFormController(); if (formController == null) { return; } if (bundle != null) { Set<String> keys = bundle.keySet(); for (String key : keys) { for (QuestionWidget questionWidget : widgets) { FormEntryPrompt prompt = questionWidget.getFormEntryPrompt(); TreeReference treeReference = (TreeReference) prompt.getFormElement().getBind().getReference(); if (treeReference.getNameLast().equals(key)) { switch (prompt.getDataType()) { case Constants.DATATYPE_TEXT: formController.saveAnswer(prompt.getIndex(), ExternalAppsUtils.asStringData(bundle.get(key))); ((StringWidget) questionWidget).setDisplayValueFromModel(); break; case Constants.DATATYPE_INTEGER: formController.saveAnswer(prompt.getIndex(), ExternalAppsUtils.asIntegerData(bundle.get(key))); ((StringWidget) questionWidget).setDisplayValueFromModel(); break; case Constants.DATATYPE_DECIMAL: formController.saveAnswer(prompt.getIndex(), ExternalAppsUtils.asDecimalData(bundle.get(key))); ((StringWidget) questionWidget).setDisplayValueFromModel(); break; case Constants.DATATYPE_BINARY: try { Uri uri = (Uri) bundle.get(key); try { File destFile = FileUtils.createDestinationMediaFile(formController.getInstanceFile().getParent(), ContentResolverHelper.getFileExtensionFromUri(getContext(), uri)); FileUtils.saveAnswerFileFromUri(uri, destFile, getContext()); ((WidgetDataReceiver) questionWidget).setData(destFile); } catch (SecurityException e) { <START> Timber.w(e); <END> } } catch (ClassCastException e) { Timber.w(e); } break; default: throw new RuntimeException( getContext().getString(R.string.ext_assign_value_error, treeReference.toString(false))); } break; } } } } }</code><technical_language>this implicitly clear existing value? I more error case missing -- if type of file passed external app match question type. For example, a .mp3 file allowed for image widget</technical_language>

Target:
public void setDataForFields(Bundle bundle) throws JavaRosaException { FormController formController = Collect.getInstance().getFormController(); if (formController == null) { return; } if (bundle != null) { Set<String> keys = bundle.keySet(); for (String key : keys) { for (QuestionWidget questionWidget : widgets) { FormEntryPrompt prompt = questionWidget.getFormEntryPrompt(); TreeReference treeReference = (TreeReference) prompt.getFormElement().getBind().getReference(); if (treeReference.getNameLast().equals(key)) { switch (prompt.getDataType()) { case Constants.DATATYPE_TEXT: formController.saveAnswer(prompt.getIndex(), ExternalAppsUtils.asStringData(bundle.get(key))); ((StringWidget) questionWidget).setDisplayValueFromModel(); break; case Constants.DATATYPE_INTEGER: formController.saveAnswer(prompt.getIndex(), ExternalAppsUtils.asIntegerData(bundle.get(key))); ((StringWidget) questionWidget).setDisplayValueFromModel(); break; case Constants.DATATYPE_DECIMAL: formController.saveAnswer(prompt.getIndex(), ExternalAppsUtils.asDecimalData(bundle.get(key))); ((StringWidget) questionWidget).setDisplayValueFromModel(); break; case Constants.DATATYPE_BINARY: try { Uri uri = (Uri) bundle.get(key); if (uri != null) { File destFile = FileUtils.createDestinationMediaFile(formController.getInstanceFile().getParent(), ContentResolverHelper.getFileExtensionFromUri(getContext(), uri)); FileUtils.saveAnswerFileFromUri(uri, destFile, getContext()); ((WidgetDataReceiver) questionWidget).setData(destFile); } } catch (Exception | Error e) { Timber.w(e); } break; default: throw new RuntimeException( getContext().getString(R.string.ext_assign_value_error, treeReference.toString(false))); } break; } } } } }