使用iOS和Android的HTML 5文件输入[Cordova/Phonegap]

Blu*_*Blu 14 html5 android ios cordova

在PhoneGap应用程序中,我尝试使用input像这样的HTML5 标签的相机.

  1. 使用CLI创建新项目
  2. 添加iOS和Android平台
  3. 添加相机插件
  4. 构建两个设备
  5. 在两台设备上运行(实际设备IPhone 5,iOS 7.1.2和Android 4.4.2(Samsung Note))

以下是我尝试执行的代码行

<input id="imageHolder" type="file" accept="image/*" capture />
Run Code Online (Sandbox Code Playgroud)

它适用于iPhone但不适用于Android.我错过了什么?或Android不支持此功能?点击Android中的字段后没有任何反应,而在iPhone中它的行为如下 文件输入在iOS中工作

Mar*_*ius 1

我发现这是一个老问题,但答案不是使用 HTML,而是使用 JavaScript 和 cordova 插件。

我用过这个插件

非常容易使用。

例子:

if (device.platform == "Android") { //Here we check to see what OS is used. input with type file is supported on iOS, but not Android. So use plugin for Android
    fileStorage.open(function (uri) {
        if (callback) {
            callback(uri);
        }
        return uri;
    }, function (ex) {
        throw ex;
    });
} else {
    var file = document.createElement("input");
    file.type = "file";
    file.accept = ".pdf";
    file.style.display = "none";

    document.body.appendChild(file);
    file.click();

    file.onchange = function (f) {
        console.log(f);

        console.log(file.files);

        var reader = new FileReader()

        reader.readAsDataURL(file.files[0]);

        reader.onloadend = function () {
            if (callback) {
                callback(reader.result);
            }

            return reader.result;
        }

        document.body.removeChild(file);
    }
}
Run Code Online (Sandbox Code Playgroud)