android - 具有捕获和接受属性的 HTML 文件输入控件工作错误?

标签 android ios html mobile

我的问题:

然后用户点击input type=file用户必须获得 upload file + camera对话。我正在使用这个 html 属性 acceptcapture .但在一些现代设备上,这不会发生。下面是代码示例和它的工作与否的表格。代码示例在 Mobile Safari 中进行测试和 Chrome .

TL;DR:

我有 5 个代码示例,只有 input type file :

1.( jsfiddle )

<input type="file" accept="image/*" capture>

2. ( jsfiddle )

<input type="file" accept="image/*" capture="camera">

3. ( jsfiddle )

<input type="file" capture="camera">

4. ( jsfiddle )

<input type="file" capture>

5. ( jsfiddle )

<input type="file" accept="image/*">

测试设备:

  • 三星 S3(Android 4.1.2)
  • 三星 S3(Android 4.3)
  • 三星 Galaxy Tab 2 7.0 (Android 4.2.2)
  • 三星 Note (Android 4.1.2)
  • iPhone 5 (iOS 7.0.4)
  • Nexus 4 (Android 4.4)

结果表:

  • W(ork) - 表示启用 upload image dialog with camera
  • P(artially works) - 表示启用 upload dialog(not image only) with camera
  • N(ot work) - 表示 only camera启用
  • Ch - 表示 Chrome
  • MS - 表示 Mobile Safari

#

--------------------------------------------------------------------------------
|devices/example   | Ch 1| Ch 2| Ch 3| Ch 4| Ch 5| MS 1| MS 2| MS 3| MS 4| MS 5| 
--------------------------------------------------------------------------------
|Samsung S3/4.1    |  N  |  N  |  P  |  P  |  W  |  W  |  N  |  P  |  P  |  W  |
--------------------------------------------------------------------------------
|Samsung S3/4.3    |  N  |  N  |  P  |  P  |  P  |  N  |  N  |  P  |  P  |  P  |
--------------------------------------------------------------------------------
|Samsung Galaxy Tab|  N  |  N  |  P  |  P  |  W  |  W  |  N  |  P  |  P  |  W  |
--------------------------------------------------------------------------------
|Samsung Note      |  N  |  N  |  P  |  P  |  W  |  W  |  N  |  P  |  P  |  W  |
--------------------------------------------------------------------------------
|iPhone 5          |  W  |  W  |  P  |  P  |  W  |  W  |  Y  |  P  |  P  |  W  |
--------------------------------------------------------------------------------
|Nexus 4           |  N  |  N  |  P  |  P  |  W  |  -  |  -  |  -  |  -  |  -  |
--------------------------------------------------------------------------------

如你所见,我只能得到 upload file + camera使用所有浏览器的对话框

<input type="file" accept="image/*">只要。但是没有capture在这种情况下属性,这让我担心,Android 4.3 存在问题。

我的问题是:

  1. 表中的行为是否正确? Android 4.3 的行为是一个错误?
  2. 对于浏览器,我可以相信它总是会添加摄像头来上传吗 没有捕获属性的对话框? (答案请添加证明链接)

谢谢。

附:问题很特殊,但在我的网站上,我必须为用户提供对其图像和相机的访问权限。另外我认为我的表格对任何人都有帮助,而且我会寻找答案,如果没有人回答,我会在这里发布我的答案。

最佳答案

这是真正的答案。只需在此处发布以供下一个用户使用:

Actually, it seems that current implementations don’t rely on the capture attribute at all, but only on the type and accept attributes: the browser displays a dialog box in which the user can choose where the file has to be taken, and the capture attribute is not taken into consideration. For example, iOS Safari relies on the accept attribute (not capture) for images and videos (not audio). Even if you don't use the accept attribute, the browser will let you choose between "Take Photo or Video" and "Choose Existing" (thanks to@firt for pointing this out).

来自 this

2016 年 2 月 17 日编辑: 此行为在设备上仍然有效。

关于android - 具有捕获和接受属性的 HTML 文件输入控件工作错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21523544/

相关文章:

android - 社交网络 FB、Twitter、G+ 等。在所有 3 个平台(iOS、Android 和黑莓)

ios - 当用 Swift 编写大型应用程序时,我是否需要使用 "init"方法?

html - 试图在我的 css 中定位一个类

ios - 如何在 PodioKit 中设置元素的邮箱/电话

javascript - 使用 Nightwatch (Selenium2) 无法找到包含 "anchor"的元素

html - 如何使用悬停叠加图像格式化文本

android - Android Studio不起作用

android - 什么是 GoogleApiClient 设计模式?

android 如何在布局开始时添加 View ?

ios - 如何快速获取subView的数据