How to extract values from FileChooserParams when onShowFileChooser() gets called?

南楼画角 提交于 2019-12-20 03:09:07

问题


We have a hybrid app that runs on Android and using webapp pages created in MVC.

We have 2 buttons - 1. Document upload - Files, Gallery options should be available when this is clicked (no camera option) 2. Camera upload - clicking on this should trigger camera app in phone.

I have following code on mvc view :

<input type="file" id="uploadFile" name="files" accept=".pdf,.jpg,.jpeg,.gif,.png" style="display:none;" />
    <input type="file" id="capture" name="LnFImage" accept="image/*" capture="capture" style="display:none;">

in BrowserFragment.java, we have 2 Intents:

    Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Intent chooseExistingPhotoIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

when onShowFileChooser() gets called, how do I know if takePhotoIntent to call or chooseExistingPhotoIntent to call based on the button clicked on page?

Is is possible to extract value from FileChooserParams to determine which button is calling onShowFileChooser() ?


回答1:


It's possible to extract accept attribute with FileChooserParams.getAcceptTypes() for more details have a look at Android documentation.

The name attribute can be extracted with FileChooserParams.getFilenameHint() link to documentation.

For capture use FileChooserParams.getMode() as described in the documentation

There is another SO question regarding this issue and the actual code that could help.



来源:https://stackoverflow.com/questions/56114296/how-to-extract-values-from-filechooserparams-when-onshowfilechooser-gets-calle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!