I would like to access the camera on an Android device (hopefully its the same for iPhones too). I'm currently writing a pure javascript application (no Ruby) using RhoMobile's 4.0 API. I've read in the docs that the Camera API has not yet been ported to 4.0, so I have to access via the 2.2 APIs. This is where I start to get lost. I believe I have all the necessary files included for the 2.2 API access via javascript:
build.yml:
extensions:
- rhoconnect-client
- rho-javascript
capabilities:
- camera
index.html (main page):
<!-- required for pre-4.0 JS API -->
<script type="text/javascript" src="/public/jquery/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="/public/jquery/jquery.json-2.4.min.js"></script>
<!-- pre-4.0 JS API -->
<script type="text/javascript" src="/public/js/rho_javascript_api.js"></script>
<!-- compatibility layer -->
<script type="text/javascript" src="/public/js/rho_common_api_noconflict.js"></script>
<!-- new Common JS API -->
<script type="text/javascript" charset="utf-8" src="/public/api/rhoapi-modules.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/jquery/jquery-1.9.1.min.js"></script>
.....
<div data-role="content">
<form action="" method="post" id="findingForm">
<button type="button" id="photoBtn">Add Photo</button>
<button type="submit" id="findingBtn">Submit</button>
</form>
</div>
application.js:
$('#photoBtn').on('click', function(e){
Rho.Camera.choose_picture(function(params) {
console.log(params);
});
});
When I click the button above, I receive the following errors in adb logcat:
I/APP (15917): I 02/11/2014 11:53:57:639 00003e42 HttpServer| Process URI: '/app/RhoJavascriptApi/command_handler'
I/APP (15917): E 02/11/2014 11:53:57:639 00003e42 HttpServer| The file /app/RhoJavascriptApi/command_handler was not found
E/Web Console(15917): Uncaught SyntaxError: Unexpected token < at http://localhost:44326/public/index.html#findings:1
It seems like the javascript code is looking for a Ruby controller or something along those lines? Or I'm completely missing something. Any help is greatly appreciated!
Device: Getac Z710 (tablet)
Android: 4.1.1
-Mark
Mark,
Camera support with the new JS APIs is expected in the 4.1 release sometime by the end of Q1.
In the meantime you might want to take a look at the RhoSpection application that uses the camera using a short ruby controller.
rho-samples/Rhospection/Rhospection/app at master · rhomobile/rho-samples · GitHub
Look in the Camera directory and Report/new.erb (Search for camera). In the Report/new.erb the ruby method for the camera is called directly.
Points: 0
You voted ‘up’
Derek,
Last week RhoMobile held a chat on Twitter to discuss the 4.1 API release. I sent this message and got the reply below:
@rossmd: @RhoMobile will 4.1 support camera functionality using a pure javascript app (no Ruby code/controllers/etc)? #RhoChat - 05 Mar 14
@adamblum: @rossmd @RhoMobile not yet. You could write your own JavaScript proxy call down to the Ruby. #rhochat
So Adam says camera functionality will NOT be in 4.1. Can you confirm if this is correct or not? If not, do you have any ideas/suggestions on how to get camera access working with what he's suggesting "Javascript proxy down to the Ruby"? It was my understanding that if I'm using javascript only (no /app folder at all), the compiler never uses Ruby (at least that Javascript has access to). If I'm wrong about that, can you explain and/or give an example of how to access Ruby from Javascript using an app with "javascript_application: true" in build.yml?
Thanks,
Mark
Points: 0
You voted ‘up’
Mark,
The Camera API did not make it in the 4.1 release. You should be able to use the 2.2 version of Javascript - take a look at this thread:
Points: 0
You voted ‘up’
I include all the correct javascript files (as mentioned in the above link), then try to access the camera from Javascript like:
I get the following error message:
I 03/13/2014 16:44:31:169 03a89000 HttpServer| Process URI: '/app/RhoJavascriptApi/command_handler'
E 03/13/2014 16:44:31:170 03a89000 HttpServer| The file /app/RhoJavascriptApi/command_handler was not found
I'm going to guess this is because I don't have any Ruby code nor an /app folder. The app folder was removed per this documentation:
Rhomobile | Using RhoMobile JavaScript API’s
Do you have any example code that uses the 2.2 Javascript API to access the Camera that does not require Ruby code/controllers?
Thanks,
Mark
Points: 0
You voted ‘up’
I'd be happy if I could get the camera API to work in 4.1 Ruby...
I build an existing 3.5.1 app with 4.1. It uses the camera API.
It opens the camera window, I can snap a picture, the camera UI closes, and, then... nothing. Something must have changed about the callback.
Need to take a look at logs yet, add logging to insure I get the callback, etc.
Any obvious known difference?
Points: 0
You voted ‘up’
Sounds like there are deteriorations in features and platform support as new Rho versions are introduced.
If it was a JS feature, I'd understand, but Ruby?
Points: 0
You voted ‘up’
Mark - actually, I was able to e.g. Photo capture to work. Work-around is to simply restart the app. However, the application terminates right after you approve access to photos. I'm assuming something needs to be re-written in application.rb.
Camera API has not yet been re-written, it is still 2.2 API.
Fairly few hiccups moving a large 2.2 app to 4.1. We abused app_info (Rho::Log) in one place and passed a hash. Apparently that worked in 2.2, but don't think was documented. It only takes a string now.
Points: 0
You voted ‘up’
Hi Jon
FYI, I used the camera on WM on v2.2 and eventually the functionality had to be withdrawn. The camera would freeze on occasion after taking a picture. Just like you describe.
So I’m not totally sure its just a 4.0/4.1 issue (Rho not Ruby).
If that helps?
Points: 0
You voted ‘up’
Hi David,
From what you're saying, I take it there are camera issues even in v2.2 ?
Points: 0
You voted ‘up’
Yes, definitely. About 1 in 5 photos would fail meaning the application needed to be terminated to recover. I was using code from the examples. I didn’t really have the time or inclination to try and work out what was going wrong, instead choosing to withdraw it as it was a low level requirement – a ‘nice to have’.
I believe the camera is still at v2.2. So not been upgraded for v4.1 yet.
I was using it on MC55A0 with WM 6.5.3. Not sure if you would get the same issues on WP, Android or iOS though.
Points: 0
You voted ‘up’