与visualforce和jquery mobile集成时,navigator.camera未定义

时间:2014-11-09 19:54:35

标签: javascript android jquery cordova

我正在尝试在我的应用中使用jquery mobile和cordova访问相机。 cordova正在完美地启动,但我无法获得navigator.camera属性。 navigator.camera总是未定义的。我相信我正确地导入了cordova并且也给了权限。

我给了

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

我的页面是

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0; user-scalable=no" />
 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
 <link rel="stylesheet" href="css/jquery.mobile.min.css" />
 <script src="js/jquery.min.js"></script>
 <script src="js/jquery.mobile.min.js"></script>
 <script src="cordova.js"></script>
 <script src="js/forcetk.mobilesdk.js"></script>

<style>
  .logWindow {display:none; width:700px;}
  .logWindow > p {padding:0px; margin:0px; word-wrap:break-word;}
</style>

<script>
var apiVersion = "v31.0";
var forcetkClient;
var debugMode = true;
var pictureSource;   // picture source
var destinationType; // sets the format of returned value
jQuery(document).ready(function() {
   document.addEventListener("deviceready", onDeviceReady,false);
});

function onDeviceReady() {
    cordova.require("com.salesforce.util.logger").logToConsole("onDeviceReady: Cordova ready");
   cordova.require("com.salesforce.plugin.oauth").getAuthCredentials(salesforceSessionRefreshed, getAuthCredentialsError);
document.addEventListener("salesforceSessionRefresh",salesforceSessionRefreshed,false);
     regLinkClickHandlers();
}
function salesforceSessionRefreshed(creds) {
    cordova.require("com.salesforce.util.logger").logToConsole("salesforceSessionRefreshed");
   var credsData = creds;
    if (creds.data)  // Event sets the `data` object with the auth data.
        credsData = creds.data;

    forcetkClient = new forcetk.Client(credsData.clientId, credsData.loginUrl, null,
        cordova.require("com.salesforce.plugin.oauth").forcetkRefresh);
    forcetkClient.setSessionToken(credsData.accessToken, apiVersion, credsData.instanceUrl);
    forcetkClient.setRefreshToken(credsData.refreshToken);
    forcetkClient.setUserAgentString(credsData.userAgent);
}

function getAuthCredentialsError(error) {
    cordova.require("com.salesforce.util.logger").logToConsole("getAuthCredentialsError: " + error);
}
function takePic() {    
    alert(navigator.camera);
    navigator.camera.getPicture(onPicSuccess, onPicFail, { quality: 50,
    destinationType: Camera.DestinationType.DATA_URL
 }); 
}

function onPicSuccess(imageData) {
    InspectionsController.saveInspectionImage(imageData, inspectionRec, 
        function(res,event){ });
}

function onPicFail(message) {
    console.log("Pic failed: " + JSON.stringify(message));
}
</script>

 <script src="inline.js"></script>       

   </head>
  <body>
     <div data-role="page" data-theme="b" id="jqm-home"> 
       <div  data-role="header"> 
          <h1>Salesforce and Device Contacts</h1> 
      </div> 

      <div id="#content" data-role="content"> 
          <a onClick="takePic();" href="#" data-theme="a" data-iconpos="top" id="picBtn" data-role="button">Take Picture</a>

          <h3>console:</h3>
          <p id="console" class="logWindow">
          </p>
      </div>  
  </div> 
</body>

我的项目结构是

enter image description here

有些人可以帮助我摆脱navigator.camera的未定义值

0 个答案:

没有答案