ET1: Access camera from hybrid application - Is there a way?

I am writing a hybrid application that needs to be able to access the camera on the ET1. If there is no access via javascript, what is the preferred method to use? Hopefully the answer is not to rewrite as a native application.

Any suggestions would be greatly appreciated.

Robert Galvin
Hi Jay  Actually you need to

Hi Jay  Actually you need to use the Imager API for the ET1 (Using the rhoelements runtime or app_type:rhoelements in a native model).  There are code snippets at: http://docs.rhomobile.com/rhoelements/imager

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
I was hopeful at first since

I was hopeful at first since the examples allowed me to figure out how to activate the camera (although all 'meta' tag values had to be transposed into the equivalent javascript format).  After a number of hours attempting to capture an image to a file I resorted to running through an example to get a working sample and hopefully to get a handle on how to use the imager object with javascript. Unfortunately the example code does not seem to work properly and there are syntax errors and malformed html. To get around this I attempted to enumerate the properties of the 'imager' object to get get a good list of object properties. This (javascript snippet below) resulted in a RhoElements runtime error and subsequent dump/force close message.

for(var prop in imager)

    {

     if(imager.hasOwnProperty(prop))

      alert(imager[prop]);

    }

It appears the the "imagerCaptureEvent" does not get wired up using javascript or html meta tags (tried it both ways - is this the correct name?). I am assuming that the event should fire when an image is captured.

<META HTTP-Equiv="Imager" Content="imagerCaptureEvent:url('Javascript:onImageCapture(%json)');">

imager.imagerCaptureEvent=onImageCapture(%json)';

Is there more up to date and complete documentation available? Or am I completely off track and doing this the wrong way? Any advice or help would be greatly appreciated.

Jay

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Additional info: It appears

Additional info: It appears that "imagerCaptureEvent" may not be the correct attribute name for the imager object's event. Some experimentation shows that any invalid name is ignored in javascript and does not throw any exception other than subsequent events not firing.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Stephen Skidmore
Jay,I have been working on

Jay,

I have been working on the same issue.  I cannot raise a capture event even though I can enable and capture using the imager object.  I have spoken to some local Motorola folks, they agree and yesterday submitted a support ticket.  At their suggestion I tried to enable cam1 and found that it will raise capture events all day long. They also tried earlier OS and runtime releases.  None made it better, some made it worse.  My ET1 has the accessory scanner so I removed it and retested, no change.  I think the only thing left is firmware?  When they get an answer I'll update this thread if they do not do it sooner.

Steve

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Peter Arcuri
The term Hybrid implies some

The term Hybrid implies some native code... perhaps this proves to be helpful.

Extended API for Motorola devices (RhoElements applications)

Take a picture:

Camera::take_picture('/app/model/camera_callback', options_hash) 

options_hash – hash contain additional parameters :

  • “left” – number, camera left position in pixels. Default value = 0
  • “top” – number, camera top position in pixels. Default value = 0
  • “desired_width” – number, desired width in pixels. Default value = max camera width
  • “desired_height” – number, desired height in pixels. Default value = max camera height

Sample

See controller and view in the /app/Image folder of the System API Samples application for more information.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Is there a tutorial/example

Is there a tutorial/example available that shows how to set up an application that uses this API? The application currently uses Javascript interfaces only.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
Are your web pages running

Are your web pages running from the device or locally on the device?

In the following code example, I set the destination to be a local file on the device. If my web pages are running locally on the device then this will probably be ok because I can reference the local file system. If my web pages are running on a web server, then I would probably want to change the destination to either be an FTP server or a HTTP web page that is ready to accept a file upload. The online help has an example showing this. Notice that I am not using the imagerCaptureEvent below. Run this and then use USB to connect to the ET1 so you can see it is capturing the image.

function imagerEnable()

{

imager.top=400

imager.width=120

imager.height=120

imager.destination = 'url("file:///image.jpg")';   // ON ET1 this will save the image captured to the SD card root as image.jpg

imager.enable();

}

function imagerCapture()

{

imager.capture();

}

The imagerCaptureEvent was recently added so that you can handle the image in a dataURI string instead of actual files. This event is supposed to fire when the dataURI is available for the image capture. In this case, I also am seeing that this is not working on the ET1. I have an email into engineering to find out what is going on.

The imagerEvent however fires when the image is copied to the location in the destination property above, so you can register for a callback when the file transfer is complete (in the case of HTTP Post or FTP).

I will respond back when I get some details around the dataURI method.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Robert,Just checking back in

Robert,

Just checking back in to see if there has been any progress made regarding this issue.

Thanks,

          Jay

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
Hi JayThe issue has to do

Hi Jay

The issue has to do with the back camera resolution causing the conversion to a Base64 DataURI to fail. We are working on a fix that should make it into the next release (2.2). You can select the front facing camera instead to get through with your testing. If the matter is urgent then we may be able to provide you with a beta 'hotfix' runtime.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
When I execute this code

When I execute this code enableImager("cam1");, the rear facing camera becomes enabled. Is there another bug with enabling the front camera using the Imager object?

PS. Enumeration of imagers on device shows:

          Imagers on device: 2

          deviceName  --  friendlyName

          cam0 -- Back Facing Camera

          cam1 -- Front Facing Camera

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Try this:imager.enabled =

Try this:

imager.enabled = 'cam1';

This works on my ET1 with REVC OS and RhoElements runtime 2.1.1.7

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Daniel,    Thanks for the tip

Daniel,

    Thanks for the tip. I mis-stated the function call in my last message. I actually had wrapped up a call to imager.enable() in my function enableImager(). That was working for the rear facing camera. Your suggestion works to enable the front facing camera, but  the imager.disable() method does not seem to work. Is there some updated documentation somewhere that shows valid methods to use?

I'm not what I am missing since the documentation (located here: http://docs.rhomobile.com/rhoelements/imager) shows:

enable enables the imager device and shows the viewer window N/A
disable disables the imager device and hides the viewer window N/A

Thanks,

          Jay

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Does not matter which camera

Does not matter which camera was enabled, imager.disable();  seems to work fine on my unit.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Daniel,     Thanks. I found

Daniel,

     Thanks. I found the error in my code. It was a matter of setting the parameter to enable and using the method to disable. It turns out that the proper usage, that is now working for me, looks something like this:

         

function enableImager(currentCam)

{

      imager.enabled=currentCam;

     //show buttons

      $('#captureButton').fadeIn("slow");      

      $('#cancelButton').fadeIn("slow");

}

function disableImager()

{

      imager.disable();

     //hide buttons

      $('#captureButton').fadeOut("fast");

      $('#cancelButton').fadeOut("fast");

}

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Robert,      I would

Robert,

     I would definitely be interested in trying out the beta 'hotfix' runtime. Unless it's possible the next release will be available before the beginning of November. My company is slated to be delivering a demo application for use in the Motorola booth at the Rockwell Automation
Fair.

Thanks,

          Jay

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
Ok having the external MSR is

Ok having the external MSR is accessory will impact how many "imagers' are on the device. What specific version of Andoid/ET1 software is being used? You should be using what has been called 'Rev C' or if you Settings/about device/Build number

Capture.PNG

Also are you using pre-production devices/accessories? Also what version of RhoElements are you using. You should be using 2.1.1.7

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jay Fisher
Rob,I verified that all

Rob,

I verified that all versions match those that you listed. Both ET1 devices purchased less than 1 month ago and updated with latest OS last week.

Imager Enumeration on device:

ET1_ImagerEnum.jpg

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Stephen Skidmore
Rob,I don't mean to hijack

Rob,

I don't mean to hijack Jay's thread but I'm not sure if you're asking me or Jay.

I don't have the MSR, we're using the ET1 scanner module. It makes sense that it would be counted as the third imager by the device but it is not included in the list when imagerEnum returns. Likewise, removing it had no effect.

Android Ver 2.3.4

Bootloader Ver 1.1.4

Kernel Ver 2.6.35.7

Build 03-271301-1852-0602-00-M1-060812

All of that looks correct and the runtime is 2.1.1.7.

The device and scanner were purchased through a distributer so I think it is a regular production device. If it helps the s/n is 11357521400247.

The device will raise and process the imagerEvent without problem but not the imagerCaptureEvent. The oddest thing is that I swear it was working then stopped.

I also captured the below from the Dalvik debugger maybe that will mean something to you?

10-05 19:15:23.406: E/MOTO plugin(2110): writing to socket 0000000001000008JSOBJECT02000006imager03000007capture09000000

10-05 19:15:23.406: E/MOTO plugin(2110):

10-05 19:15:23.406: E/MOTO plugin(2110): wrote 62 characters

10-05 19:15:23.414: E/BaseCameraAdapter(1575): hardware/ti/omap3/camera-omap4/src/BaseCameraAdapter.cpp:169 enableMsgType - Message type subscription no supported yet!

10-05 19:15:23.859: E/AudioHardwareALSA(1575): RE-OPEN AFTER STANDBY:: took 56 msecs

10-05 19:15:24.078: E/OMXCameraAdapter(1575): hardware/ti/omap3/camera-omap4/src/OMXCameraAdapter/OMXCameraAdapter.cpp:2555 SignalEvent - Event queue empty!!!

10-05 19:15:24.078: E/OMXCapture(1575): hardware/ti/omap3/camera-omap4/src/OMXCameraAdapter/OMXCapture.cpp:861 stopImageCapture - Timeout expired on shutter callback

10-05 19:15:25.898: E/BaseCameraAdapter(1575): hardware/ti/omap3/camera-omap4/src/BaseCameraAdapter.cpp:223 disableMsgType - Message type 0x200 subscription no supported yet!

10-05 19:15:26.750: E/JavaBinder(1667): !!! FAILED BINDER TRANSACTION !!!

10-05 19:15:26.976: E/Omap4ALSA(1575): called drain&close

I just received a VM from my Motorola contact saying that support has reproduced the issue and it has been forwarded to Engineering.

Steve

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Nrusingha Chara...
There is an issue in 2.1.1.7

There is an issue in 2.1.1.7 for imagerCaptureEvent (data URI) with ET1 back camera but imagerCaptureEvent (data URI) works fine with FrontCamera of ET1

The code snippet suggested by Rob should work fine to capture an image and store it in SD card for ET1

Regards,

Patro

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments