首页 > 解决方案 > 调用 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 还是调用chooseExistingPhotoIntent

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

标签: androidandroid-intentinputandroid-webviewfilechooser

解决方案


可以通过查看Android 文档来提取accept属性以获取更多详细信息。FileChooserParams.getAcceptTypes()

name可以通过FileChooserParams.getFilenameHint() 文档链接提取该属性。

按照文档中的capture说明使用FileChooserParams.getMode()

关于这个问题还有另一个SO question以及可以提供帮助的实际代码。


推荐阅读