【问题标题】:PhoneGap Camera , Cannot read property 'getPicture' of undefinedPhoneGap 相机,无法读取未定义的属性“getPicture”
【发布时间】:2014-08-29 00:39:37
【问题描述】:

我正在尝试让相机 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);
    }
};
});

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

编辑:所以在听从阿拉文的建议后,我添加了&lt;script src="cordova.js"&gt;&lt;/script&gt; 现在它至少看起来正在发生一些事情,但现在我在我的 eclipse logcat 中得到了这些错误:

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

【问题讨论】:

  • 你是在模拟器还是移动设备上运行?
  • 好吧,在设备上什么都没有发生,在浏览器上我得到了那个错误
  • 在浏览器中,你会得到这个“未定义”的错误。因为 phonegap API 只有在您将其包装为 build(ipa,apk..) 时才会起作用。
  • 显示你的 cordova.js 的位置
  • cordova.js 通常会在哪里......对不起,我作为团队的一员在做这件事,所以我没有自己做所有事情

标签: javascript html angularjs cordova phonegap-plugins


【解决方案1】:

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

【讨论】:

  • 我也犯了同样的错误。你能解释一下你做了什么吗?如果您可以更详细地编辑您的答案,您可以帮助其他人。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    总的解决方法如下..

    您需要在 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 2020-03-21
      • 2022-01-02
      • 1970-01-01
      相关资源
      最近更新 更多