eclipse - Unable to access camera after adding plugin and feature and use permission in phonegap android project -


i trying access camera in android phone.

i did steps still unable access. using latest phonegap , have installed plugins , have added permission in manifest.xml file , added features in config.xml.

still stuck :(

can please?

following files.

html

        <!doctype html>         <html>         <head>          <title>capture photo</title>           <script type="text/javascript" charset="utf-8" src="cordova.js"></script>          <script type="text/javascript" charset="utf-8">           var picturesource;   // picture source          var destinationtype; // sets format of returned value          // wait device api libraries load        //        document.addeventlistener("deviceready", ondeviceready, false);      // device apis available     //     function ondeviceready() {           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);          picturesource = navigator.camera.picturesourcetype;         destinationtype = navigator.camera.destinationtype;           alert('ondeviceready! after');       }      // called when photo retrieved     //     function onphotodatasuccess(imagedata) {         // uncomment view base64-encoded image data         // console.log(imagedata);          // image handle         //         alert("onphotodatasuccess.");         var smallimage = document.getelementbyid('smallimage');          // unhide image elements         //         smallimage.style.display = 'block';          // show captured photo         // in-line css rules used resize image         //         smallimage.src = "data:image/jpeg;base64," + imagedata;     }      // called when photo retrieved     //     function onphotourisuccess(imageuri) {         // uncomment view image file uri         // console.log(imageuri);          // image handle         //         var largeimage = document.getelementbyid('largeimage');          // unhide image elements         //         largeimage.style.display = 'block';          // show captured photo         // in-line css rules used resize image         //         largeimage.src = imageuri;     }      // button call function     //     function capturephoto() {         alert("hi");         // take picture using device camera , retrieve image base64-encoded string         navigator.camera.getpicture(onphotodatasuccess, onfail, {             quality: 50,             destinationtype: destinationtype.data_url         });     }      // button call function     //     function capturephotoedit() {         // take picture using device camera, allow edit, , retrieve image base64-encoded     string         navigator.camera.getpicture(onphotodatasuccess, onfail, {             quality: 20, allowedit: true,             destinationtype: destinationtype.data_url         });     }      // button call function     //     function getphoto(source) {         // retrieve image file location specified source         alert("get photo.");         navigator.camera.getpicture(onphotourisuccess, onfail, {             quality: 50,             destinationtype: destinationtype.file_uri,             sourcetype: source         });         alert("get photo done.");     }      // called if bad happens.     //     function onfail(message) {         alert('failed because: ' + message);     }     </script>    </head>    <body>  <button onclick="capturephoto();">capture photo</button> <br>  <button onclick="capturephotoedit();">capture editable photo</button> <br>  <button onclick="getphoto(picturesource.photolibrary);">from photo library</button><br>  <button onclick="getphoto(picturesource.savedphotoalbum);">from photo album</button><br>  <img style="display:none;width:60px;height:60px;" id="smallimage" src="" />  <img style="display:none;" id="largeimage" src="" />  </body>  </html> 

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.inf.cameracheck"  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" />            <uses-permission android:name="android.permission.camera"/>            <uses-feature android:name="android.hardware.camera"/>            <uses-feature android:name="android.hardware.camera.autofocus"/>            <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="camchk" andr  oid: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="19" />         <uses-permission android:name="android.permission.access_coarse_location" />            <uses-permission android:name="android.permission.access_fine_location" />           <uses-permission android:name="android.permission.write_external_storage" />            <uses-permission android:name="android.permission.record_audio" />             <uses-permission android:name="android.permission.record_video" />              <uses-permission android:name="android.permission.modify_audio_settings" />             <uses-permission android:name="android.permission.read_phone_state" />            </manifest> 

config.xml

<?xml version="1.0" encoding="utf-8"?> <widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.inf.cameracheck" version="1.0.0">     <name>hello cordova</name>     <description>a sample apache cordova application responds deviceready event.</description>     <access origin="*" />     <content src="index.html" />     <preference name="loglevel" value="debug" />     <feature name="app">         <param name="android-package" value="org.apache.cordova.app" />     </feature>     <name>camchk</name>     <description>hello world sample application responds deviceready event.</description>     <author email="support@phonegap.com" href="http://phonegap.com">phonegap team</author>     <feature name="http://api.phonegap.com/1.0/device" />     <preference name="permissions" value="none" />     <preference name="orientation" value="default" />     <preference name="target-device" value="universal" />     <preference name="fullscreen" value="true" />     <preference name="webviewbounce" value="true" />     <preference name="prerendered-icon" value="true" />     <preference name="stay-in-webview" value="false" />     <preference name="ios-statusbarstyle" value="black-opaque" />     <preference name="detect-data-types" value="true" />     <preference name="exit-on-suspend" value="false" />     <preference name="show-splash-screen-spinner" value="true" />     <preference name="auto-hide-splash-screen" value="true" />     <preference name="disable-cursor" value="false" />     <preference name="android-minsdkversion" value="7" />     <preference name="android-installlocation" value="auto" />     <icon src="icon.png" />     <icon gap:density="ldpi" gap:platform="android" src="res/icon/android/icon-36-ldpi.png" />     <icon gap:density="mdpi" gap:platform="android" src="res/icon/android/icon-48-mdpi.png" />     <icon gap:density="hdpi" gap:platform="android" src="res/icon/android/icon-72-hdpi.png" />     <icon gap:density="xhdpi" gap:platform="android" src="res/icon/android/icon-96-xhdpi.png" />     <icon gap:platform="blackberry" src="res/icon/blackberry/icon-80.png" />     <icon gap:platform="blackberry" gap:state="hover" src="res/icon/blackberry/icon-80.png" />     <icon gap:platform="ios" height="57" src="res/icon/ios/icon-57.png" width="57" />     <icon gap:platform="ios" height="72" src="res/icon/ios/icon-72.png" width="72" />     <icon gap:platform="ios" height="114" src="res/icon/ios/icon-57-2x.png" width="114" />     <icon gap:platform="ios" height="144" src="res/icon/ios/icon-72-2x.png" width="144" />     <icon gap:platform="webos" src="res/icon/webos/icon-64.png" />     <icon gap:platform="winphone" src="res/icon/windows-phone/icon-48.png" />     <icon gap:platform="winphone" gap:role="background" src="res/icon/windows-phone/icon-  173.png" />     <gap:splash gap:density="ldpi" gap:platform="android" src="res/screen/android/screen-ldpi-portrait.png" />     <gap:splash gap:density="mdpi" gap:platform="android" src="res/screen/android/screen-mdpi-portrait.png" />     <gap:splash gap:density="hdpi" gap:platform="android" src="res/screen/android/screen-hdpi-portrait.png" />     <gap:splash gap:density="xhdpi" gap:platform="android" src="res/screen/android/screen-xhdpi-portrait.png" />     <gap:splash gap:platform="blackberry" src="res/screen/blackberry/screen-225.png" />     <gap:splash gap:platform="ios" height="480" src="res/screen/ios/screen-iphone-portrait.png" width="320" />     <gap:splash gap:platform="ios" height="960" src="res/screen/ios/screen-iphone-portrait-2x.png" width="640" />     <gap:splash gap:platform="ios" height="1024" src="res/screen/ios/screen-ipad-portrait.png" width="768" />     <gap:splash gap:platform="ios" height="768" src="res/screen/ios/screen-ipad-landscape.png" width="1024" />     <gap:splash gap:platform="winphone" src="res/screen/windows-phone/screen-portrait.jpg" />     <access origin="http://127.0.0.1*" />     <feature name="device">         <param name="android-package" value="org.apache.cordova.device.device" />     </feature>     <feature name="accelerometer">         <param name="android-package" value="org.apache.cordova.devicemotion.accellistener" />     </feature>     <feature name="compass">         <param name="android-package" value="org.apache.cordova.deviceorientation.compasslistener" />     </feature>     <feature name="geolocation">         <param name="android-package" value="org.apache.cordova.geolocation.geobroker" />     </feature>     <feature name="camera">         <param name="android-package" value="org.apache.cordova.camera.cameralauncher" />     </feature>     <feature name="file">         <param name="android-package" value="org.apache.cordova.file.fileutils" />         <param name="onload" value="true" />     </feature>     <feature name="capture">         <param name="android-package" value="org.apache.cordova.mediacapture.capture" />     </feature>     <feature name="media">         <param name="android-package" value="org.apache.cordova.media.audiohandler" />     </feature> </widget> 

i suggest change javascript code this

var picturesource; // picture source var destinationtype; // sets format of returned value // wait device api libraries load // document.addeventlistener("deviceready", ondeviceready, false); // device apis available //  function ondeviceready() {     picturesource = navigator.camera.picturesourcetype;     destinationtype = navigator.camera.destinationtype; } // called when photo retrieved //  function onphotodatasuccess(imageuri) {     // uncomment view base64-encoded image data     // console.log(imagedata);     // image handle     //     var smallimage = document.getelementbyid('smallimage');     // unhide image elements     //     smallimage.style.display = 'block';     // show captured photo     // inline css rules used resize image     //     smallimage.src = imageuri; } // called when photo retrieved //  function onphotourisuccess(imageuri) {     // uncomment view image file uri     // console.log(imageuri);     // image handle     //     var largeimage = document.getelementbyid('largeimage');     // unhide image elements     //     largeimage.style.display = 'block';     // show captured photo     // inline css rules used resize image     //     largeimage.src = imageuri; } // button call function //  function capturephoto() {     // take picture using device camera , retrieve image base64-encoded string     navigator.camera.getpicture(onphotodatasuccess, onfail, {         quality: 50,         destinationtype: destinationtype.file_uri     }); } // button call function //  function capturephotoedit() {     // take picture using device camera, allow edit, , retrieve image base64-encoded string     navigator.camera.getpicture(onphotodatasuccess, onfail, {         quality: 20,         allowedit: true,         destinationtype: destinationtype.data_url     }); } // button call function //  function getphoto(source) {     // retrieve image file location specified source     navigator.camera.getpicture(onphotourisuccess, onfail, {         quality: 50,         destinationtype: destinationtype.file_uri,         sourcetype: source     }); } // called if bad happens. //  function onfail(message) {     alert('failed because: ' + message); } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -