onDeviceReady() の後でカメラ プラグイン オブジェクトをインスタンス化できません。ナビゲーター オブジェクトは問題ありませんが、navigator.camera === 未定義であり、後続のカメラ メソッド呼び出しで爆発します。カメラプラグインは問題なくインストールされましたが、構成の問題であると確信しています。下をのぞくための追加の岩が足りなくなりました。よろしくお願いします。ここに私のファイルがあります:
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); }
構成.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>
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>