我们有一个在 Android 上运行并使用在 MVC 中创建的 Web 应用程序页面的混合应用程序。
我们有 2 个按钮 - 1. 文档上传 - 单击此按钮时,文件、图库选项应该可用(无相机选项) 2. 相机上传 - 单击此按钮将触发手机中的相机应用程序。
我在 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;">
在BrowserFragment.java中,我们有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);
当onShowFileChooser()被调用时,我如何根据页面上点击的按钮知道是takePhotoIntent调用还是chooseExistingPhotoIntent调用?
是否可以从 FileChooserParams 中提取值来确定哪个按钮正在调用 onShowFileChooser() ?
最佳答案
可以使用 FileChooserParams.getAcceptTypes()
提取 accept
属性,了解更多详细信息,请查看 Android documentation 。
可以使用FileChooserParams.getFilenameHint()
提取name
属性link to documentation 。
对于捕获
,请使用FileChooserParams.getMode()
as described in the documentation
还有一个SO question关于这个问题以及可能有帮助的实际代码。
关于android - 调用 onShowFileChooser() 时如何从 FileChooserParams 中提取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56114296/