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

标签 android android-intent input android-webview filechooser

我们有一个在 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/

相关文章:

android - 在 React Native 中加载屏幕时如何滚动到顶部?

java - 启动 IntentService 的空指针异常

android - 如何在android中从一个类移动到另一个类

java - 如何在 8 秒内完成 Ads_Fullscreen Activity 并在之后执行 MainActivity?

android 打开 ("/dev/input/event1", O_RDWR);权限被拒绝?

visual-studio - Visual Studio 在键盘上运行缓慢、键盘延迟和从键盘输入中随机重复击键

Haskell 读取 Prec 有理函数

android - 闹钟提醒不起作用

android - 我可以检查默认的音频编码器吗?

android - 调用另一个应用程序,并发送包名为 Android 的数据