android - 调用 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() ?
解决方案
可以通过查看Android 文档来提取accept
属性以获取更多详细信息。FileChooserParams.getAcceptTypes()
name
可以通过FileChooserParams.getFilenameHint()
文档链接提取该属性。
按照文档中的capture
说明使用FileChooserParams.getMode()
关于这个问题还有另一个SO question以及可以提供帮助的实际代码。
推荐阅读
- asp.net-web-api - 使用 Gmail 和 Web Api 发送电子邮件失败
- python - 添加阴影以突出显示 matplotlib 中的重叠元素
- sql - 如何使用openjson交叉应用具有多个对象的json,例如: [{"id":"xxx","values":"xxx"},{"id":"zzz","values":"zzz" }]?
- python - 使用 AES_256 算法破译从 ping 身份到 python 烧瓶应用程序的 SAML 响应
- python - 如何使用python断言对象属性不存在?
- graphql - WordPress woocomerce graphql 失败
- export-to-csv - Powershell 中对多个 CSV 文件的单个查询结果
- c# - 以 Unity (2D) 的速度将对象移动到某个位置
- pointers - 依赖共享邮件服务器发送邮件的 VPS 上的 rDNS
- grafana - 在 grafana 中设置警报 | 百分位数与百分比