2016-04-11 83 views
0

不能正常工作,我們需要得到的圖像格式Gallery.So我們加入插件,我們的應用程序,然後我們試圖這樣從畫廊得到圖像中的PhoneGap

var pictureSource; // picture source 
    var destinationType; // sets the format of returned value 
document.addEventListener("deviceready",onDeviceReady,false); 
function onDeviceReady() { 
     alert("ondevicereday"); 
     pictureSource=navigator.camera.PictureSourceType; 
     destinationType=navigator.camera.DestinationType; 
    } 
    function onPhotoDataSuccess(imageData) { 
    alert("Open"); 
     var smallImage = document.getElementById('smallImage'); 
     smallImage.src = "data:image/jpeg;base64," + imageData; 
    } 
function capturePhoto(){ 
    alert("justOpen"); 
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
     destinationType: destinationType.FILE_URI, 
     sourceType: Camera.PictureSourceType.PHOTOLIBRARY }); 

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

但我們無法打開gallery.When頁面載入「ondevicereday 「警報顯示,然後我們點擊openGallery按鈕,它顯示justOpen警報,但我們無法打開 所以請指導我們,告訴我什麼錯碼

+0

任何錯誤跟蹤? – Gandhi

+0

重命名'onPhotoDataSuccess'爲'onPhotoURISuccess' – Akis

+0

@Naveen Dodda你設法解決? – IamKarim1992

回答

0

我已經impalmented科爾多瓦這個使用文件API插件,文件API插件會讓你訪問Android手機中的文件系統。

這裏是鏈接https://github.com/wymsee/cordova-imagePicker

<!DOCTYPE html> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 
--> 
<html> 
    <head> 
     <!-- 
     Customize this policy to fit your own app's needs. For more guidance, see: 
      https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy 
     Some notes: 
      * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication 
      * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly 
      * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: 
       * Enable inline JS: add 'unsafe-inline' to default-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> 
       <button style="width:30%;" onclick="pickImage()">Clean Data</button> 
       <p id="lastPhoto"></p> 
      </div> 
     </div> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
     <script type="text/javascript" src="js/jquery.min.js"></script> 
     <script type="text/javascript"> 
      function pickImage(){ 
       var lastPhotoContainer = document.getElementById("lastPhoto"); 
       var doc= document.getElementBy 
       window.imagePicker.getPictures(
       function(results) { 
        console.log(results); 
         for (var i = 0; i < results.length; i++) { 
         var imageUri=results[i]; 
         console.log('Image URI: ' + results[i]); 
         lastPhotoContainer.innerHTML = "<img src='" + imageUri + "' style='width: 75%;' />"; 
         } 
        }, function (error) { 
         console.log('Error: ' + error); 
       } 
      ); 
      } 
     </script> 
    </body> 
</html> 

這個簡單的例子,從本地存儲需要一個單一的圖像,並顯示其應用程序的屏幕上,U可以繼續前進,將圖像從URI爲base64轉換並使用它作爲你喜歡的。現在這將填充已經採取的圖片到HTML ..希望這有助於。