[英]PhoneGap Camera , Cannot read property 'getPicture' of undefined
I am trying to get the Camera API to work in my PhoneGap android app, but i keep getting this error 我想让Camera API在我的PhoneGap android应用程序中工作,但我一直收到这个错误
"Cannot read property 'getPicture' of undefined". “无法读取未定义的属性'getPicture'”。
Now i have checked countless answers on StackOverflow and tutorials all over the web,and tried all the answer there(with no luck), and i cant seem to find the issue. 现在我已经在整个网络上检查了StackOverflow和教程的无数答案,并尝试了所有的答案(没有运气),我似乎无法找到问题。
This is the button that calls the function 这是调用该函数的按钮
<button type="button" class="btn btn-primary" ng-click="getPic()">Camera</button>
This is the controller that handles the camera 这是处理相机的控制器
myApp.controller('EditProfileCtrl', function ($scope, $http, navigateFactory) {
$scope.getPic = function () {
navigator.camera.getPicture(onSuccess, onFail, {
quality: 60,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: 1
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed beause' + message);
}
};
});
Please comment if there is any additional information required. 如果需要任何其他信息,请发表评论。 Any and all help will be hugely appreciated. 任何和所有的帮助将非常感激。
EDIT: So after following Aravin's advice i added <script src="cordova.js"></script>
now it atleast looks like something is happening, but now im getting these errors in my eclipse logcat: 编辑:所以在遵循Aravin的建议之后我添加了<script src="cordova.js"></script>
现在它至少看起来正在发生什么,但现在我在我的eclipse logcat中得到这些错误:
I/System.out(3871): Error adding plugin org.apache.cordova.CameraLauncher D/PluginManager(3871): exec() call to unknown plugin: Camera I / System.out(3871):添加插件时出错org.apache.cordova.CameraLauncher D / PluginManager(3871):exec()调用未知插件:相机
The total work around is below.. 总的工作在下面..
you need to write all code in your html page. 你需要在你的html页面中编写所有代码。
<body>
<div data-role="page">
<script type="text/javascript">
function getPhotoFromCamera() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 50,
sourceType: navigator.camera.PictureSourceType.CAMERA,
destinationType: navigator.camera.DestinationType.DATA_URL,
});
}
function onPhotoDataSuccess(imageData){
var image = document.getElementById('image');
image.style.display = 'block';
image.src = "data:image/jpeg;base64,"+imageData;
}
function getPhotoFromAlbum(){
navigator.camera.getPicture(onPhotoURISuccess, onFail,{
quality: 50,
sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: navigator.camera.DestinationType.FILE_URI
});
}
function onPhotoURISuccess(imageURI){
var image = document.getElementById('image');
image.style.display = 'block';
image.src = imageURI;
}
function onFail(message){
alert('Failed because:' + message);
}
</script>
<div data-role="header" style="height:36px;">
<h1>Write New</h1>
<a href="#" data-icon="arrow-l" data-rel="back">Back</a>
</div>
<button onclick="getPhotoFromCamera();">Launch Camera</button>
<button onclick="getPhotoFromAlbum();">Goto Picture Gallery</button>
<div>
<img id="image" style="display:none;width;290px;height:210px;" src = ""/>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
So after trying all the things here with no success I did this which fixed the issue (dont know how)... 所以在尝试了所有的事情之后没有成功我做了这个解决了问题(不知道如何)......
remove the plugin , build , add the plugin , build 删除插件,构建,添加插件,构建
and Magic! 和魔术!
如果您正在使用TFS,请记得在安装插件之前检查编辑“fetch.json”,否则它将在安装中失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.