繁体   English   中英

PhoneGap Camera,无法读取未定义的属性'getPicture'

[英]PhoneGap Camera , Cannot read property 'getPicture' of undefined

我想让Camera API在我的PhoneGap android应用程序中工作,但我一直收到这个错误

“无法读取未定义的属性'getPicture'”。

现在我已经在整个网络上检查了StackOverflow和教程的无数答案,并尝试了所有的答案(没有运气),我似乎无法找到问题。

这是调用该函数的按钮

<button type="button" class="btn btn-primary" ng-click="getPic()">Camera</button>

这是处理相机的控制器

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);
    }
};
});

如果需要任何其他信息,请发表评论。 任何和所有的帮助将非常感激。

编辑:所以在遵循Aravin的建议之后我添加了<script src="cordova.js"></script>现在它至少看起来正在发生什么,但现在我在我的eclipse logcat中得到这些错误:

I / System.out(3871):添加插件时出错org.apache.cordova.CameraLauncher D / PluginManager(3871):exec()调用未知插件:相机

总的工作在下面..

你需要在你的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>

所以在尝试了所有的事情之后没有成功我做了这个解决了问题(不知道如何)......
删除插件,构建,添加插件,构建
和魔术!

如果您正在使用TFS,请记得在安装插件之前检查编辑“fetch.json”,否则它将在安装中失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM