Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: Android
    • Environment:

      Phonegap Sample App

      Droid 3 with current updates (Android 2.3.4)

      Native (for droid 3) camera app.

      Description

      1. In the sample app, click the button to take a picture.
      2. The camera app launches, take a picture, and tap done.
      3. The sample app reappears but there is no indication that the picture was taken.

      I made a simple app to test this, which should simply alert the FILE_URI result, or alert something on error. Neither callbacks are hit, instead the app restarts. If you view the logcat, it shows a console.log() right before launching the camera, and the next log message after taking the picture shows a new PID and other logs related to the app starting.

      This happens in any app I have tried this with, even the simplest "take a picture and alert the path" app. It also happens with alternative camera apps. I've tried a couple of 3rd party camera apps with the same outcome.

      This might be related - They describe the exact behavior I see, but I tried using their modified phonegap.jar with no luck.

      https://groups.google.com/group/phonegap/browse_thread/thread/185c2fd8eb6270ac/db973ebc78d6b4b6?lnk=gst&q=%22droid+3%22#db973ebc78d6b4b6

      index.html
      <!DOCTYPE html>
      <html>
        <head>
          <title>Capture Image</title>
      
      	<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
          <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
          <script type="text/javascript" charset="utf-8">
      
          var defaultPictureOptions = {
          		quality : 50,
          		destinationType: Camera.DestinationType.FILE_URI,
          		sourceType: Camera.PictureSourceType.CAMERA
          		/* ,
          		targetWidth: 100,
          		targetHeight: 100
          		*/
          	};
      
      
          	var phonegapPic = function(onSuccess, onFail, photoType) {
          		if (!navigator) { console.log('no navigator obj'); return false; }
          		if (!navigator.camera) { console.log('no navigator.camera obj'); return false;  }
          		if (!navigator.camera.getPicture) { console.log('no navigator.camera.getPicture'); return false; }
      
          		photoType = photoType || "camera";
      
          		console.log('taking picture...');
          		var opts = $.extend({}, defaultPictureOptions, {
          			sourceType: (photoType === "camera") ? Camera.PictureSourceType.CAMERA : Camera.PictureSourceType.PHOTOLIBRARY
          		});
      
          		navigator.camera.getPicture(onSuccess, onFail, opts);
          		return true;
          	};
          	
          	
          	function captureImage()
          	{
          		phonegapPic( function( imgURI ){ alert( 'got picture: ' + imgURI ); },
          				function(){ alert( 'error!' )} );
          	}
          </script>
          </head>
          <body>
              <button onclick="captureImage();">Capture Image</button> <br>
          </body>
      </html>
      

        Activity

        Hide
        Simon MacDonald added a comment -

        Please confirm that your android activity has the following attribute:

        android:configChanges="orientation|keyboardHidden"

        Show
        Simon MacDonald added a comment - Please confirm that your android activity has the following attribute: android:configChanges="orientation|keyboardHidden"
        Hide
        John Reeves added a comment -

        Yes, I do have that.

        Show
        John Reeves added a comment - Yes, I do have that.
        Hide
        Alan Neveu added a comment -

        I just experienced this exact same issue on a Droid 3. This thread describes the behavior exactly. I searched around the web and found these two posts that seem like they will help PhoneGap work around this issue:

        http://community.developer.motorola.com/t5/Android-App-Development-for/Moto-Backflip-Camera-crashes-while-calling-from-intent/td-p/5254

        and this one:

        http://andrea.levinge.me/?p=132

        Looking forward to some resolution on this, definitely not PhoneGap's fault but it would be fantastic if we could resolve this at the PG layer. Thanks!

        Show
        Alan Neveu added a comment - I just experienced this exact same issue on a Droid 3. This thread describes the behavior exactly. I searched around the web and found these two posts that seem like they will help PhoneGap work around this issue: http://community.developer.motorola.com/t5/Android-App-Development-for/Moto-Backflip-Camera-crashes-while-calling-from-intent/td-p/5254 and this one: http://andrea.levinge.me/?p=132 Looking forward to some resolution on this, definitely not PhoneGap's fault but it would be fantastic if we could resolve this at the PG layer. Thanks!
        Hide
        Simon MacDonald added a comment -

        Alan Neveu, I can build you a jar with that fix in it if you are willing to test.

        Show
        Simon MacDonald added a comment - Alan Neveu, I can build you a jar with that fix in it if you are willing to test.
        Hide
        Chip Matthes added a comment -

        This is probably the same problem as issue CB-193.

        Show
        Chip Matthes added a comment - This is probably the same problem as issue CB-193 .
        Hide
        John Reeves added a comment -

        I don't think it is related to CB-193. That was closed as a duplicate of CB-14, which has to do with out of memory errors. I noted specifically that I am requesting a file URI, not a data string. I'm not sure if there is some other reason it could run out of memory, but I think CB-14 was probably caused when people do something that causes reading the file. Just my input.

        Show
        John Reeves added a comment - I don't think it is related to CB-193 . That was closed as a duplicate of CB-14 , which has to do with out of memory errors. I noted specifically that I am requesting a file URI, not a data string. I'm not sure if there is some other reason it could run out of memory, but I think CB-14 was probably caused when people do something that causes reading the file. Just my input.
        Hide
        Alan Neveu added a comment -





        Well, my issue is with returning a base64 encoded image, not with the File URI. Simon, do you still think you might have a fix? I am only using PG Build so a jar won't help me at this time. Perhaps if I point you at my PG Build project?

        Show
        Alan Neveu added a comment - Well, my issue is with returning a base64 encoded image, not with the File URI. Simon, do you still think you might have a fix? I am only using PG Build so a jar won't help me at this time. Perhaps if I point you at my PG Build project?
        Hide
        Simon MacDonald added a comment -

        Hey Alan,

        Using the DATA_URL return is a bad idea. As the cameras get better in phones the size of the images captured is getting bigger and bigger. When you request a Base64 encoded version of images from a 5 or 8 mega pixel camera it will cause and out of memory error. Wherever possible I suggest people use the FILE_URI return type.

        Show
        Simon MacDonald added a comment - Hey Alan, Using the DATA_URL return is a bad idea. As the cameras get better in phones the size of the images captured is getting bigger and bigger. When you request a Base64 encoded version of images from a 5 or 8 mega pixel camera it will cause and out of memory error. Wherever possible I suggest people use the FILE_URI return type.
        Hide
        Alan Neveu added a comment -

        Okay, great suggestion, thanks. Question... For our app we will never want an image any larger than something like 1280 x 1024. So is it safe to use DATA_URL if we are requesting height and width of something like 1024 x 768? I did see some out of memory errors in BlackBerry but using height and width of 1024 x 768 seemed to resolve that. So my questions are:

        1) Do you think it is safe to use DATA_URL if we always pass a height and width no more than 1280 x 768?

        2) If we use File URI how can we scale the image down before uploading it to a web server? We certainly don't want to send the whole image to a web server and scale it server side, simply because it would mean a huge upload that would take a long time and be prone to failures. We could use something like Pixastic and shrink the image using HTML5 canvas, but it does not work on BlackBerry OS5 (or 6, I think). We are really targeting only iOS, Android, BB, and WP7.

        Many thanks in advance!

        Show
        Alan Neveu added a comment - Okay, great suggestion, thanks. Question... For our app we will never want an image any larger than something like 1280 x 1024. So is it safe to use DATA_URL if we are requesting height and width of something like 1024 x 768? I did see some out of memory errors in BlackBerry but using height and width of 1024 x 768 seemed to resolve that. So my questions are: 1) Do you think it is safe to use DATA_URL if we always pass a height and width no more than 1280 x 768? 2) If we use File URI how can we scale the image down before uploading it to a web server? We certainly don't want to send the whole image to a web server and scale it server side, simply because it would mean a huge upload that would take a long time and be prone to failures. We could use something like Pixastic and shrink the image using HTML5 canvas, but it does not work on BlackBerry OS5 (or 6, I think). We are really targeting only iOS, Android, BB, and WP7. Many thanks in advance!
        Hide
        Simon MacDonald added a comment -

        I would use FILE_URI with the targetWidgth and targetHeight parameters as it would be the safest way to get what you want.

        Show
        Simon MacDonald added a comment - I would use FILE_URI with the targetWidgth and targetHeight parameters as it would be the safest way to get what you want.
        Hide
        Alan Neveu added a comment -

        How is this any different from using DATA_URL? If I have to read the file bytes and base64 encode anyway, there should be no difference whether I get the same result using DATA_URL or FILE_URI. Unless there is something more under the API level that I am not aware of. Can you enlighten me? Are you saying that using FILE_URI will work across all Android devices, even the Moto Droid3, which is demonstrated to cause the app to restart when using DATA_URL? Any insights you can give on this will save me and other many other developers endless grief. Many thanks!

        Show
        Alan Neveu added a comment - How is this any different from using DATA_URL? If I have to read the file bytes and base64 encode anyway, there should be no difference whether I get the same result using DATA_URL or FILE_URI. Unless there is something more under the API level that I am not aware of. Can you enlighten me? Are you saying that using FILE_URI will work across all Android devices, even the Moto Droid3, which is demonstrated to cause the app to restart when using DATA_URL? Any insights you can give on this will save me and other many other developers endless grief. Many thanks!
        Hide
        John Reeves added a comment -

        This probably isn't the place to discuss the differences between DATA_URL and FILE_URI. But since I already started, I think the point is you should avoid ever using a base64 encoded version of your photos. I mean, what purpose does that serve? You can reference it by its FILE_URI to display it, and you can send it to the server with FileTransfer. If you were planning on doing some sort of image manipulation in your app, then I don't know what your options are, but they probably still don't include using a base64 encoded string of image data.

        If you still want to talk about this, I suggest heading over to #phonegap on irc.freenode.net. They've been pretty helpful for me.

        Show
        John Reeves added a comment - This probably isn't the place to discuss the differences between DATA_URL and FILE_URI. But since I already started, I think the point is you should avoid ever using a base64 encoded version of your photos. I mean, what purpose does that serve? You can reference it by its FILE_URI to display it, and you can send it to the server with FileTransfer. If you were planning on doing some sort of image manipulation in your app, then I don't know what your options are, but they probably still don't include using a base64 encoded string of image data. If you still want to talk about this, I suggest heading over to #phonegap on irc.freenode.net. They've been pretty helpful for me.
        Hide
        Alan Neveu added a comment -

        I apologize for any inappropriateness of this question. The purpose of base64 encoding is so that we can send it to a web service in chunks while giving good user feedback about the upload progress, check MD5 hashes of each chunk to ensure no image corruption, add application level metadata along with the image, and more. But your response of using FileTransfer instead is a good one that we will certainly consider. Thanks for that!

        Show
        Alan Neveu added a comment - I apologize for any inappropriateness of this question. The purpose of base64 encoding is so that we can send it to a web service in chunks while giving good user feedback about the upload progress, check MD5 hashes of each chunk to ensure no image corruption, add application level metadata along with the image, and more. But your response of using FileTransfer instead is a good one that we will certainly consider. Thanks for that!
        Hide
        Joe Bowser added a comment -

        Assigning it to you since you're already working on this anyway, and have a fix.

        Show
        Joe Bowser added a comment - Assigning it to you since you're already working on this anyway, and have a fix.
        Hide
        Joe Bowser added a comment -

        Unable to reproduce on Motorola RAZR running Android 2.3.5 with Motoblur.

        Show
        Joe Bowser added a comment - Unable to reproduce on Motorola RAZR running Android 2.3.5 with Motoblur.
        Hide
        John Reeves added a comment -

        Woah woah woah, don't resolve it as cannot reproduce. The environment, description, and comments were all about Droid 3 and 2.3.4.

        You might as well resolve it as cannot reproduce on the iPhone if that's how you roll.

        Show
        John Reeves added a comment - Woah woah woah, don't resolve it as cannot reproduce. The environment, description, and comments were all about Droid 3 and 2.3.4. You might as well resolve it as cannot reproduce on the iPhone if that's how you roll.
        Hide
        Filip Maj added a comment -

        Agreed, let's keep it open until we have that device on-hand and can test it out.

        Show
        Filip Maj added a comment - Agreed, let's keep it open until we have that device on-hand and can test it out.
        Hide
        Filip Maj added a comment -

        No promises on when we will deliver a fix as we first need to hunt down a device, which is an expensive venture.

        Show
        Filip Maj added a comment - No promises on when we will deliver a fix as we first need to hunt down a device, which is an expensive venture.
        Hide
        John Reeves added a comment -

        True, good point. I understand that difficulty. I'm no longer working on the same project at work that caused me to find the issue, but maybe when I get some free time at home I can help debugging this issue more (it was my phone I found it on, but have sinced installed a custom rom because Motoblur).

        Show
        John Reeves added a comment - True, good point. I understand that difficulty. I'm no longer working on the same project at work that caused me to find the issue, but maybe when I get some free time at home I can help debugging this issue more (it was my phone I found it on, but have sinced installed a custom rom because Motoblur).
        Hide
        Joe Bowser added a comment -

        As much as we would like to, it is not feasible for us to purchase every single Android device on the market to test with, therefore we currently try to pick devices that are representative of their manufacturers. The fact is that the device is a Motorola device, and the device has Motoblur installed, as does the Backflip and the Droid 3. This may have a later version of Motoblur, but the fact is that it worked on the RAZR that we purchased to test Motoblur bugs on. This may mean that a Motorola update will fix it, or it may mean it's an issue that is confined to your device.

        Can you provide a more generic test case, perhaps one that works on the Motorola Emulation Suite?

        Show
        Joe Bowser added a comment - As much as we would like to, it is not feasible for us to purchase every single Android device on the market to test with, therefore we currently try to pick devices that are representative of their manufacturers. The fact is that the device is a Motorola device, and the device has Motoblur installed, as does the Backflip and the Droid 3. This may have a later version of Motoblur, but the fact is that it worked on the RAZR that we purchased to test Motoblur bugs on. This may mean that a Motorola update will fix it, or it may mean it's an issue that is confined to your device. Can you provide a more generic test case, perhaps one that works on the Motorola Emulation Suite?
        Hide
        Filip Maj added a comment -

        Joe, you are correct, but marking as "cannot reproduce" is misleading. There is no harm in leaving the bug open. Perhaps someone else from the community has the device and can help identify and solve the problem down the road.

        At least we can point to this issue if someone else stumbles upon it. "Known Issue"!

        Show
        Filip Maj added a comment - Joe, you are correct, but marking as "cannot reproduce" is misleading. There is no harm in leaving the bug open. Perhaps someone else from the community has the device and can help identify and solve the problem down the road. At least we can point to this issue if someone else stumbles upon it. "Known Issue"!
        Hide
        Joe Bowser added a comment -

        OK, if we do that, I propose that we lower the priority on it, since that's also misleading.

        Show
        Joe Bowser added a comment - OK, if we do that, I propose that we lower the priority on it, since that's also misleading.
        Hide
        Filip Maj added a comment -

        Sounds good to me.

        Show
        Filip Maj added a comment - Sounds good to me.
        Hide
        Anis Kadri added a comment -

        Good day,

        I tried a slightly modified example below (without jQuery) on a Verizon Wireless Motorola Droid 3 and I could not reproduce the issue. I've tried about 20 times. I got confused as to why Cordova sends a content:// URI back but it was not actually causing problems. I believe the fact that the image might not be written yet when the Camera activity returns might cause the issue you're describing. However, I wasn't able to reproduce it.

         
        <!DOCTYPE html>
        <html>
          <head>
            <title>Capture Image</title>
            <script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
            <script type="text/javascript" charset="utf-8">
            	var phonegapPic = function(onSuccess, onFail, photoType) {
                    var defaultPictureOptions = {
                        quality : 50,
                        destinationType: Camera.DestinationType.FILE_URI,
                        sourceType: Camera.PictureSourceType.CAMERA
                    };
            		if (!navigator) { console.log('no navigator obj'); return false; }
            		if (!navigator.camera) { console.log('no navigator.camera obj'); return false;  }
            		if (!navigator.camera.getPicture) { console.log('no navigator.camera.getPicture'); return false; }
        
            		photoType = photoType || "camera";
        
            		console.log('taking picture...');
                    var opts = defaultPictureOptions;
            		navigator.camera.getPicture(onSuccess, onFail, opts);
            		return true;
            	};
            	
            	
            	function captureImage()
            	{
            		phonegapPic( function( imgURI ){ 
                                    alert( 'got picture: ' + imgURI ); 
                                    var img = document.getElementById("testImg");
                                    img.src = imgURI;
                            },
            				function(){ alert( 'error!' )} );
            	}
            </script>
            </head>
            <body>
                <button id="captureBtn" onclick="captureImage();">Capture Image</button> <br>
                <img src="" id="testImg" />
            </body>
        </html>
        
        
        Show
        Anis Kadri added a comment - Good day, I tried a slightly modified example below (without jQuery) on a Verizon Wireless Motorola Droid 3 and I could not reproduce the issue. I've tried about 20 times. I got confused as to why Cordova sends a content:// URI back but it was not actually causing problems. I believe the fact that the image might not be written yet when the Camera activity returns might cause the issue you're describing. However, I wasn't able to reproduce it. <!DOCTYPE html> <html> <head> <title> Capture Image </title> <script type= "text/javascript" charset= "utf-8" src= "cordova-1.5.0.js" > </script> <script type= "text/javascript" charset= "utf-8" > var phonegapPic = function(onSuccess, onFail, photoType) { var defaultPictureOptions = { quality : 50, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.CAMERA }; if (!navigator) { console.log('no navigator obj'); return false; } if (!navigator.camera) { console.log('no navigator.camera obj'); return false; } if (!navigator.camera.getPicture) { console.log('no navigator.camera.getPicture'); return false; } photoType = photoType || "camera" ; console.log('taking picture...'); var opts = defaultPictureOptions; navigator.camera.getPicture(onSuccess, onFail, opts); return true; }; function captureImage() { phonegapPic( function( imgURI ){ alert( 'got picture: ' + imgURI ); var img = document.getElementById( "testImg" ); img.src = imgURI; }, function(){ alert( 'error!' )} ); } </script> </head> <body> <button id= "captureBtn" onclick= "captureImage();" > Capture Image </button> <br> <img src= "" id=" testImg" /> </body> </html>
        Hide
        Anis Kadri added a comment -

        Could not reproduce on a verizon wireless motorola droid 3

        Show
        Anis Kadri added a comment - Could not reproduce on a verizon wireless motorola droid 3
        Hide
        Filip Maj added a comment -

        Hey Anis,

        What version of Android is your device running?

        Show
        Filip Maj added a comment - Hey Anis, What version of Android is your device running?
        Hide
        Anis Kadri added a comment -

        2.3.4

        Show
        Anis Kadri added a comment - 2.3.4
        Hide
        Aaron Moore added a comment -

        I can reproduce on a Droid 3 running 2.3.4 - not rooted or modded.
        I cannot reproduce on a Droid 3 running SteelDroid 5.3 and android 4.0.4.

        Choosing a picture from the photolibrary seems to work fine and calls my success function. Taking a picture from the camera and accepting returns to the app but never calls either success or failure.

        Show
        Aaron Moore added a comment - I can reproduce on a Droid 3 running 2.3.4 - not rooted or modded. I cannot reproduce on a Droid 3 running SteelDroid 5.3 and android 4.0.4. Choosing a picture from the photolibrary seems to work fine and calls my success function. Taking a picture from the camera and accepting returns to the app but never calls either success or failure.
        Hide
        Rainer Wahnsinn added a comment -

        Please reopen!! Exactly the same issue on Samsung Galaxy W with Phonegap 2.0.0 and jquery mobile. no call of success or failure just restart . Here is the log http://pastebin.com/3xRAe3QH

        Show
        Rainer Wahnsinn added a comment - Please reopen!! Exactly the same issue on Samsung Galaxy W with Phonegap 2.0.0 and jquery mobile. no call of success or failure just restart . Here is the log http://pastebin.com/3xRAe3QH

          People

          • Assignee:
            Unassigned
            Reporter:
            John Reeves
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development