0

I am currently working on a project that needs to use a mobile camera device to make photos and send them to a remote server.

The problem is that we don’t need a mobile native application, but a web application with all the code deployed on a remote server. For example a JavaScript code that can make photos and deploy them to a server. I wonder if it is possible to use the Camera feature in such a way ?

I tried Geolocation API of gwt-phonegap 1.8.1 on Samsung Galaxy S3 with Andoird 4.0.3 where web application was hosted on a remote server and it worked fine but when I try to open the camera and take a picture, then only a TODO picture was shown. Is the problem on my side or is this feature not implemented yet or it’s just not supposed to work that way?

Here is a snippet from my code that shows actual camera usage

PictureOptions options = new PictureOptions(25); 
        options.setDestinationType(PictureOptions.DESTINATION_TYPE_DATA_URL); 
        options.setSourceType(PictureOptions.PICTURE_SOURCE_TYPE_CAMERA); 

        final Image image = new Image(); 

        if (phoneGap.getCamera() != null) { 
          message += "camera was detected and we are trying to take a photo"; 

          phoneGap.getCamera().getPicture(options, new PictureCallback() { 

            public void onSuccess(String data) { 
//        display.setImageData("data:image/jpeg;base64," + data); 
              image.setUrl("data:image/jpeg;base64," + data); 
              panel.add(image); 
            } 

            @Override 
            public void onFailure(String message) { 
              Window.alert("Photo not successful"); 
            } 

          }); 

        } else { 
          message += "camera was not detected"; 
          message += " " + phoneGap.getClass().getName(); 

        } 

        label.setText(message);
Adelin
  • 18,144
  • 26
  • 115
  • 175

1 Answers1

1

You could either use an <input type=file> with a special accept attribute value (requires interaction from the user), or the getUserMedia API.

See http://www.html5rocks.com/en/tutorials/getusermedia/intro/ for detailsand some sample code.

In GWT, you'd have to use JSNI or the Elemental library to use the getUserMedia API.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164