javascript - PhoneGap 3.0.0 : Unable To Instantiate Camera Plugin Object

标签 javascript android plugins cordova camera

我无法在 onDeviceReady() 之后实例化相机插件对象。 navigator 对象很好,但是 navigator.camera === undefined 会在后续的相机方法调用中爆炸。相机插件安装没有发生任何事件,但我确定它是一个配置问题。刚刚用完额外的岩石来窥视。预先感谢您的帮助。这是我的文件:

  1. JS

    <script type="text/javascript" src="../../phonegap.js"></script>
    <script type="text/javascript" src="../../js/vendor/jquery/jquery.2.0.3.min.js"></script>
    <script type="text/javascript">
    
    function formResize() {
    
        $('.btnlink').css('width', parseInt($('.form01').css('width').replace('px', '')));
        $('.form_wrapper').css('margin-top', parseInt($('.globalhdr').css('height').replace('px', '')) + 25);
        }
        $('window').resize(function() {
            formResize();
        });
    }
    var pictureSource;   // picture source
        var destinationType; // sets the format of returned value
    
        // Wait for device API libraries to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);
    
        // device APIs are available
        //
        function onDeviceReady() {
            try {
                alert('onDeviceReady!');
                alert('navigator = ' + navigator);
                alert('navigator.camera = ' + navigator.camera);
                alert('navigator.camera.DestinationType = ' + navigator.camera.DestinationType);
                //                pictureSource=navigator.camera.PictureSourceType;
                destinationType = navigator.camera.DestinationType;            // navigator.camera.DestinationType;
                alert('destinationType = ' + destinationType);
            }
            catch(e) {
                alert(e);
            }
        }
        // A button will call this function
        //
        function capturePhoto() {
            alert('capturePhoto enter');
            // Take picture using device camera and retrieve image as base64-encoded string
            navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: destinationType.DATA_URL });
            alert('capturePhoto exit');
        }
    
        $('#camera').on('click', function(e) {
            try {
                e.preventDefault();
                capturePhoto();
            }
            catch(e) {
                alert(e);
            }
        });
    
        // Called when a photo is successfully retrieved
        //
        function onPhotoDataSuccess(imageData) {
            alert('onPhotoDataSuccess enter');
            // Uncomment to view the base64-encoded image data
            // console.log(imageData);
    
            // Get image handle
            //
            var capturedImg = $('#capturedImg');
    
            // Unhide image elements
            //
            capturedImg.css('display', 'block');
    
            // Show the captured photo
            // The inline CSS rules are used to resize the image
            //
            capturedImg.src = "data:image/jpeg;base64," + imageData;
            alert('onPhotoDataSuccess exit');
        }
    
        // Called if something bad happens.
        //
        function onFail(message) {
            alert('Failed because: ' + message);
        }
    
  2. Config.xml

    <widget id="com.phonegap.hello-world" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
        <name>MyApp</name>
        <description>
            Hello World sample application that responds to the deviceready event.
        </description>
        <author email="email@email.com" href="">MyApp Team</author>
        <feature name="Camera">
            <param name="android-package" value="org.apache.cordova.CameraLauncher" />
        </feature>
        <feature name="http://api.phonegap.com/1.0/device" />
        <!--<plugins>-->
            <!--<plugin name="Camera" value="org.apache.cordova.camera" />-->
        <!--</plugins>-->
        <!-- more -->
    </widget>
    
  3. AndroidManifest.xml

    <?xml version='1.0' encoding='utf-8'?>
        <manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="com.phonegap.hello_world" xmlns:android="http://schemas.android.com/apk/res/android">
            <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
            <uses-permission android:name="android.permission.INTERNET" />
            <application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
                <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="BlackDollShows" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
            </application>
            <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        </manifest>
    

最佳答案

已解决!

替换

<script type="text/javascript" src="../../phonegap.js"></script>

<script type="text/javascript" src="../../cordova.js"></script>

很简单,但需要很多技巧。希望对您的项目有所帮助。

关于javascript - PhoneGap 3.0.0 : Unable To Instantiate Camera Plugin Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19255731/

相关文章:

javascript - 当您不知道 ID 时启用顺序选择菜单

javascript - JavaScript 模态对话框是否可以只对选项卡模态而不对整个浏览器窗口模态?

android - 自动启动 (BOOT_COMPLETED) 在 Nomi 平板电脑上不起作用

javascript - 将 admob 广告实现到 Cordova Javascript 应用程序中

android - Flutter 中使用 dart 的视频编辑器

php - wordpress插件如何添加内容?

wordpress - WP Rest api v2 帖子过滤器按 'search' 和 'category_name' 不起作用

javascript - 谷歌仪表不显示

javascript - Polymer:使用不同 View 模型多次使用元素

Android map API v2 : Polyline gets drawn under tile overlay