2013-10-08 23 views
1

我無法在onDeviceReady()之後實例化相機插件對象。導航對象很好,但navigator.camera === undefined在隨後的攝像頭方法調用中爆炸。相機插件與事件安裝,但我相信它的配置問題。剛剛跑出更多的岩石偷看下。預先感謝您的幫助。下面是我的文件:PhoneGap 3.0.0:無法實例化相機插件對象

  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 protected]" 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> 
    

回答

0

已解決!

更換

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

隨着

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

簡單,但它花了很多雜技。希望它對你的項目有所幫助。