Worklight 6.0 移动浏览器模拟器支持 Cordova 2.6 API。对于 navigator.camera.getPicture,可以在 WL 6.0 中使用以下目标类型:
Camera.DestinationType = {
DATA_URL : 0, // Return image as base64 encoded string
FILE_URI : 1, // Return image file URI
NATIVE_URI : 2 // Return image native URI (eg. assets-library:// on iOS or content:// on Android)
};
例子:
navigator.camera.getPicture(
function(data) {
document.getElementById('camera_status').innerHTML = "Success: picture located at " + data;
var img = document.getElementById('camera_image');
img.style.display = "none";
},
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('camera_status').innerHTML = "Error getting picture.";
},
{ quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM, encodingType: fileType});
尝试清除浏览器缓存,然后确保在移动浏览器模拟器启动时接受小程序权限对话框。还要确保您的文件权限允许从 C:/Users//cordova/internal/sim/camera/ 文件夹传输,因为这是小程序存储相机 sim 图像内容的位置。
Cordova 2.6 相机 API 参考:
http ://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html