在 PhoneGap 应用程序中,我尝试使用 HTML5 使用相机input
像这样的标签。
- 使用 CLI 创建新项目
- 添加iOS和Android平台
- 添加相机插件
- 为两种设备构建
- 在两台设备上运行(实际设备 iPhone 5,配备 iOS 7.1.2 和 Android 4.4.2(三星注))
以下是我尝试执行的代码行
<input id="imageHolder" type="file" accept="image/*" capture />
It works in iPhone but not in Android. What have I missed? Or is this not supported in Android?
After tapping on the field in Android nothing happens while in iPhone it acts like below
我发现这是一个老问题,但答案不是使用 HTML,而是使用 JavaScript 和 cordova 插件。
我用过这个plugin https://github.com/DFranzen/cordova-FileStorage#readme
非常容易使用。
Example:
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);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)