微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

调用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和可能有用的实际代码.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐