调用onShowFileChooser()时如何从FileChooserParams中提取值?

我们有一个混合应用程序,可在Android上运行并使用在MVC中创建的webapp页面.

我们有2个按钮-
1.文档上传-单击此选项后,“文件,图库”选项应该可用(无相机选项)
2.相机上传-单击此按钮应会触发手机中的相机应用.

我在mvc视图上有以下代码

<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;">

browserFragment.java中,我们有2个Intent:

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

当onShowFileChooser()被调用时,如何根据页面上单击的按钮知道是否要调用takePhotoIntent或selectExistingPhotoIntent来调用

是否可以从FileChooserParams中提取值以确定哪个按钮正在调用onShowFileChooser()?

解决方法:

可以使用FileChooserParams.getAcceptTypes()提取accept属性,有关更多详细信息,请参见Android documentation.

可以使用FileChooserParams.getFilenameHint()link to documentation提取name属性.

要捕获,请使用FileChooserParams.getMode()as described in the documentation

还有另一个关于此问题的SO question和可能有用的实际代码.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...