Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8264881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:36:50+00:00 2026-06-08T04:36:50+00:00

var camera = { settings : { quality : 50, targetWidth : 1024, targetHeight

  • 0
var camera = {
  settings : {
    quality : 50,
    targetWidth : 1024,
    targetHeight : 1024,
    correctOrientation : true
  }
};
var error = function(message) {
  alert("Error happened while trying to get a picture", message);
};
document.addEventListener("deviceready", function() {
  camera.toFile = function() {
    this.settings.destinationType = navigator.camera.DestinationType.FILE_URI;
    return this;
  },
  camera.toBase64 = function() {
    this.settings.destinationType = navigator.camera.DestinationType.DATA_URL;
    return this;
  },
  camera.fromCamera = function() {
    this.settings.sourceType = navigator.camera.PictureSourceType.CAMERA;
    return this;
  };
  camera.fromLibrary = function() {
    this.settings.sourceType = navigator.camera.PictureSourceType.PHOTOLIBRARY;
    return this;
  };
  camera.fromPhotoAlbum = function() {
    this.settings.sourceType = navigator.camera.PictureSourceType.SAVEDPHOTOALBUM;
    return this;
  }
  camera.get = function(callback) {
    navigator.camera.getPicture(function(data) {
      alert("taking a picture successful");
      callback(data);
    }, error, camera.settings);
  };
}, false);

This is my small wrapper for the camera. And I call it like this:

camera.fromPhotoAlbum().toBase64().get(function(base64){});

About 20% of the time, the “alert(“taking a picture successful”);” is not called, while no error is shown. If I cancel taking a picture, an alert with the message “Error happened while trying to get a picture” is shown, so the error callback works.

Basically nothing happens. I’ve tested it on a Samsung Galaxy S2 on CM9 and a brand new HTC One X.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:36:52+00:00Added an answer on June 8, 2026 at 4:36 am

    There was another question recently about this same problem that I answered. We ran into this at my company and solved it. It has more to do with the Android system than Phonegap.

    What’s happening is when you start the camera, your app goes into onStop(). While there, the Android system has the right to kill your app if it needs memory. It just so happens that memory usually gets low when the camera takes a picture and dumps it into memory, so there’s a good chance your app will get killed while your user takes a picture.

    Now that your app is dead, when the camera finishes, it restarts your app. That’s why it’s acting so weird; the camera comes back into your app, but not the same instance that it had before, so your callback never gets called, since it doesn’t exist anymore.

    You can reduce the frequency at which this occurs by reducing the quality of the picture and passing it by URI instead of data to your app, but the problem won’t go away completely.

    To work around the callback never happening, we made a Java callback that starts the camera and saves the picture to the same location every time it takes one. Then, when the app starts back up from getting killed, it looks in that location for the picture.

    It’s a weird solution to a stupid problem, but if your app gets killed, that camera callback simply won’t happen. If you need more information on how to make the Java callback to do this, let me know and I’ll put our code up here. Otherwise, take a look at this SO answer for more info.

    EDIT: Here’s the code we use in our main DroidGap activity:

    private static final String folderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/appName";
    private static final String filePath = "phonegapImage.jpg";
    
    @Override
    public void onCreate(Bundle savedState) {
        //...The rest of onCreate, this makes the Java available in JavaScript
        appView.addJavascriptInterface(this, "Camera");
    }
    
    public void takePhoto(final String callback) {
        Log.v("Camera Plugin", "Starting takePhoto callback");
    
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(folderPath, filePath)));
        startActivityForResult(intent, TAKE_PICTURE);
    }
    
    public String getPhotoUri() {
        return Uri.fromFile(new File(folderPath, filePath)).toString();
    }
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    
        switch (requestCode) {
            case TAKE_PICTURE:
                if (resultCode == Activity.RESULT_OK) {
                    //Do whatever you need to do when the camera returns
                    //This is after the picture is already saved, we return to the page
                }
                break;
            default:
                Log.v("Camera", "Something strange happened...");
                break;
        }
    }
    

    Then, in your JavaScript, you can invoke the camera with:

    Camera.takePhoto("onPhotoURISuccess");
    //Then, to get the location of the photo after you take it and load the page again
    var imgPath = Camera.getPhotoUri();
    

    So, that’s about it. Just make sure to change all of the path/file/page/etc names to what you want to use in your app. This will overwrite that image every time a picture is taken, but you can probably figure something out to dynamically name them if you don’t want that. You can use that URI just as you would any other path in your JavaScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var messageSpan; function createFlashMessage = function(message, type, time) { messageSpan || (messageSpan = $(<span>).hide().appendTo(body));
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
var Foo = Foo || {}; Foo.Controller = (function ($) { var $page =
var JavascriptHelper = Backbone.Model.extend(JavascriptHelper, {}, // never initialized as an instance { myFn: function()
We've tried the next code: var scene = new THREE.Scene(); var camera = new
This is how a camera is instantiated: var camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT,
this is my flash as3 code : var cam:Camera; cam= Camera.getCamera(); var video:Video=new Video(200,200);
private var _product:Product; [Bindable] public function get product():Product { return _product; } public function
var gethtml = $(#topmenu > li.l89 a).text().split(' ')[1].replaceWith('Any World'); The text is not changing
var SalesforceOAuthPlugin = { /** * Obtain authentication credentials, calling 'authenticate' only if necessary.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.