科尔多瓦相机&捕获

时间:2016-02-06 07:19:58

标签: javascript android cordova camera cordova-plugins

我在这里尝试过很多关于cordova相机插件的解决方案,但我的相机仍未启动。我正在使用cordova和普通的html css和javascript。我正在研究android平台。

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git

此命令修改特定于平台的配置设置

(在app / res / xml / config.xml中)

<feature name="Camera">
<param name="android-package" value="org.apache.cordova.CameraLauncher" />

(在app / AndroidManifest中)

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

然后我将以下内容写入我的index.html:

<!DOCTYPE html>

    

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <title>Hello World</title>
</head>
<body>
    <div class="app">
        <h1>Apache Cordova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
        <h1>Apache cordova test zone</h1>
        <div class="test-zone" id="test-zone">
          <image id="image" width="100%" height="100%" />
        </div>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>

</body>

而index.js如下 -

var app = {
initialize: function() {
    this.bindEvents();
    this.testZone = {};
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    app.receivedEvent('deviceready');
    app.testZone = document.getElementById("test-zone");
    app.useGetPicture();
},
useGetPicture: function(){
  navigator.camera.getPicture(
    app.onPhotoSuccess,
    app.onFail,
    {
      quality : 75,
      destinationType : Camera.DestinationType.DATA_URL,
      sourceType      : Camera.PictureSourceType.CAMERA,
      encodingType    : Camera.EncodingType.JPEG,
      correctOrientation  : true
    }
  );
},

onPhotoSuccess: function(imageData){
  var image = document.getElementById("image");
  image.src = "data:image/jpeg;base64," + imageData;
},

onFail: function(message){
  alert('Failed: '+message);
}

// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}
};

app.initialize();

构建相机后没有出现。我没有得到我做错的地方或者这样做的正确方法。

Output Img

0 个答案:

没有答案