Takatsugu Shigeta created CB-11129:
--------------------------------------

             Summary: Cannot fire onSuccess handler on getPicture
                 Key: CB-11129
                 URL: https://issues.apache.org/jira/browse/CB-11129
             Project: Apache Cordova
          Issue Type: Bug
          Components: Plugin Camera
         Environment: OS X El Capitan (10.11.4)

{code}
$ cordova platform ls
Installed platforms:
  android 5.1.1
Available platforms:
  amazon-fireos ~3.6.3 (deprecated)
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  ios ~4.1.0
  osx ~4.0.1
  webos ~3.7.0
{code}

{code}
$ cordova plugin ls
cordova-plugin-camera 2.2.0 "Camera"
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-whitelist 1.2.2 "Whitelist"
{code}

----
Android Studio 2.0
Build on April 5, 2016

----
Device

Nexus 5
Android 6.0.1

            Reporter: Takatsugu Shigeta


I wrote following sample, but getPicture cannot fire onSuccess handler. 

Reproducing steps is like below.

----
Building environment

* First of all, I ran following commands.
{code}
$ cordova create myApp org.apache.cordova.myApp myApp
$ cd myApp/
$ cordova plugin add cordova-plugin-camera --save
$ cordova platform add android --save
$ cordova requirements android
{code}

* Next, run Android Studio, then choose "Import project (Eclipse ADT, Gradle, 
etc.)" to above myApp directory.

* Edit two files, assets/www/js/index.js and assets/www/index.html.

{code:title=index.js}
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // 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');
    },
    // 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);

        navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
            destinationType: Camera.DestinationType.FILE_URI
        });

    }
};

app.initialize();

function onSuccess(imageURI) {
    alert(imageURI);
    var image = document.getElementById('myImage');
    image.src = imageURI;
}

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

{code:title=index.html}
<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 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>
            <div>
                <img src="" id="myImage" width="500px" />
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>
{code}

* Connect Nexus 5 to My Mac.

* Try to run on Android Studio

* On Nexus 5, display camera window after allowing permissions, then take a 
picture.

* You should see URL on alert. And you should see the image. But getPicture 
cannot fire onSuccess handler. So I cannot see them.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to