Cordova 相机插件未启动相机
Cordova camera plugin not launching camera
我创建了一个 Ionic 应用程序,我需要相机功能,以便用户可以拍照并将其发送到网络服务。我关注了 Ionic 的 following guide。
基本上你只是 cd
进入你的应用程序
cd myApp
那你运行
cordova plugin add org.apache.cordova.camera
安装插件后,您可以在应用程序的任何位置调用它的功能(因为根据 Cordova,navigator.camera
是一个全局对象)。在我的例子中,我只是在我的一个控制器中执行此操作,在使用 ng-click
单击按钮后调用以下函数:
$scope.takePhoto = function() {
navigator.camera.getPicture(function(imageURI) {
// imageURI is the URL of the image that we can use for
// an <img> element or backgroundImage.
}, function(err) {
// Ruh-roh, something bad happened
}, cameraOptions);
}
但它什么都不做.. 现在我已经按照 Ionic 所说的我必须对 'T' 做的事情进行了操作,仅此而已。还有什么我应该做的吗?也许编辑 config.xml
?可能值得一提的是,这是我第一次尝试使用任何类型的 Cordova 插件。
我刚刚使用下面的代码解决了这个问题,
$scope.takePhoto = function() {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
destinationType: 0
});
function onSuccess(imageData) {
alert('onSuccess');
console.log("data:image/jpeg;base64,"+imageData);
}
function onFail(message) {
alert('Failed because: ' + message);
}
};
imageData 是您拍摄的图像的 src
我创建了一个 Ionic 应用程序,我需要相机功能,以便用户可以拍照并将其发送到网络服务。我关注了 Ionic 的 following guide。
基本上你只是 cd
进入你的应用程序
cd myApp
那你运行
cordova plugin add org.apache.cordova.camera
安装插件后,您可以在应用程序的任何位置调用它的功能(因为根据 Cordova,navigator.camera
是一个全局对象)。在我的例子中,我只是在我的一个控制器中执行此操作,在使用 ng-click
单击按钮后调用以下函数:
$scope.takePhoto = function() {
navigator.camera.getPicture(function(imageURI) {
// imageURI is the URL of the image that we can use for
// an <img> element or backgroundImage.
}, function(err) {
// Ruh-roh, something bad happened
}, cameraOptions);
}
但它什么都不做.. 现在我已经按照 Ionic 所说的我必须对 'T' 做的事情进行了操作,仅此而已。还有什么我应该做的吗?也许编辑 config.xml
?可能值得一提的是,这是我第一次尝试使用任何类型的 Cordova 插件。
我刚刚使用下面的代码解决了这个问题,
$scope.takePhoto = function() {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
destinationType: 0
});
function onSuccess(imageData) {
alert('onSuccess');
console.log("data:image/jpeg;base64,"+imageData);
}
function onFail(message) {
alert('Failed because: ' + message);
}
};
imageData 是您拍摄的图像的 src