Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
adebayooriyomi
Posts: 18
Registered: ‎01-09-2014
My Device: Blackberry 10
My Carrier: Virgin Mobile

BlackBerry 10 Webworks 2.0 Camera api

Hello Blackberry Dev,

 

Please, is there a working  Webworks 2.0 sample app for the camera example you have in the page below...

 

http://developer.blackberry.com/html5/apis/beta/cordova_camera_camera.md.html

 

I have spent over 3 weeks trying to make a simple camera work... All I get is this error

 

 

"TypeError 'undefined' is not an object (evaluating 'navigator.camera.getPicture')

 

I have tried everything I know but no solution please..

 

I will appreciate a working sample camera app link... 

 

Thanks in advance..

 

 

Please use plain text.
New Contributor
Keab42
Posts: 5
Registered: ‎12-23-2013
My Device: Z10
My Carrier: N/A

Re: BlackBerry 10 Webworks 2.0 Camera api

So you've got your Cordova Project.

 

I'm going to assume you're using Cordova 3.x and are using the Cordova command line tools. Have you added the camera plugin to your Cordova project?

 

 

Please use plain text.
New Developer
adebayooriyomi
Posts: 18
Registered: ‎01-09-2014
My Device: Blackberry 10
My Carrier: Virgin Mobile

Re: BlackBerry 10 Webworks 2.0 Camera api

Yes cordova 3.2.0.. the default cordova  that came with webworks 2.0 build and install project... and yes I have added the camera plugin through CL to my project... but still getting the same error :smileysad:

Please use plain text.
New Contributor
Keab42
Posts: 5
Registered: ‎12-23-2013
My Device: Z10
My Carrier: N/A

Re: BlackBerry 10 Webworks 2.0 Camera api

In that case it should be as simple as:

 

 

function takePicture() {
    navigator.camera.getPicture(onPictureSuccess, onPictureFail, { quality: 50,
    destinationType: Camera.DestinationType.FILE_URI });
}

function onPictureSuccess(imageURI) {
    var image = document.getElementById('myImage');
    image.src=imageURI;
}

function onPictureFail(message) {
    alert('Failed because: ' + message);
}

 

I'm guessing you have a button somewhere in the app to open the camera, so listen for the user tapping that and call takePicture().

Please use plain text.
New Developer
adebayooriyomi
Posts: 18
Registered: ‎01-09-2014
My Device: Blackberry 10
My Carrier: Virgin Mobile

Re: BlackBerry 10 Webworks 2.0 Camera api

Do you know of any tutorial link or Webworks camera sample I can checkout just to see what I am doing wrong... :smileysad:

I saw this camera sample on Git hub/ blackberry...

https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/camera/app/index.html

but it's confusing and different from what they have in the camera api on this page...

http://developer.blackberry.com/html5/apis/beta/cordova_camera_camera.md.html

if you have any tutorials on how to set it up like the example on the webworks camera api link. http://developer.blackberry.com/html5/apis/beta/cordova_camera_camera.md.html
.. or suggestion on the right cordova.js that works with webwork 2.0 ... I will appreciate ...


Thanks
Please use plain text.
New Developer
adebayooriyomi
Posts: 18
Registered: ‎01-09-2014
My Device: Blackberry 10
My Carrier: Virgin Mobile

Re: BlackBerry 10 Webworks 2.0 Camera api

Ok... I will try this new code as soon as I get back to my desk... thanks :smileyhappy:
Please use plain text.
New Contributor
Keab42
Posts: 5
Registered: ‎12-23-2013
My Device: Z10
My Carrier: N/A

Re: BlackBerry 10 Webworks 2.0 Camera api

[ Edited ]

Their sample app seems to just upload an image to a server. I'm not sure how it actually captures the image in the first place.

The second link definitely uses the cordova camera plugin, so you can always take a look at the Cordova documentation, though at first glance it appears as though BB are just recycling that on the link you've got there.

I've used Cordova 3.2.0 and 3.3.0 with Webworks 2.0 and launching the camera app really is as simple as the example I've given you in my previous post.

 

*EDIT*

 

There is a full example at the bottom of the second link.

Please use plain text.
New Developer
adebayooriyomi
Posts: 18
Registered: ‎01-09-2014
My Device: Blackberry 10
My Carrier: Virgin Mobile

Re: BlackBerry 10 Webworks 2.0 Camera api

For some reasons I can't get this to work.... I don't know what I am doing wrong.... Help me !!!!!!!!!!!!!

 

www/index.html

 

<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova_plugins.js"></script>
<script type="text/javascript" charset="utf-8">

var pictureSource; // picture source
var destinationType; // sets the format of returned value


document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}

function takePicture() {
navigator.camera.getPicture(onPictureSuccess, onFail, { quality: 50,
destinationType: Camera.destinationType.FILE_URL });
}

function onPictureSuccess(imageURI) {

var image = document.getElementById('myImage');

image.src=imageURI;
}



function onPictureFail(message) {
alert('Failed because: ' + message);
}

</script>
</head>
<body>
<button onclick="takePicture();">Take Photo</button> <br>
</body>

 

www/config.xml

 

<widget id="NewCameraTest" version="0.0.1"
xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>WebWorks Application</name>
<description>A sample Apache Cordova application that responds to the deviceready event.</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">Apache Cordova Team</author>
<content src="index.html"/>
<access origin="*"/>
<preference name="fullscreen" value="true"/>
<preference name="webviewbounce" value="true"/>
<feature id="blackberry.media.camera" />
<rim:smileytongue:ermissions>
<rim:smileytongue:ermit>use_camera</rim:smileytongue:ermit>
</rim:smileytongue:ermissions>
<feature name="Camera">
<param name="blackberry-package" value="org.apache.cordova.camera.Camera" />
</feature>

</widget>

 

 

my blackberry 10 www folder

 

config.xml

cordova_plugins.js

cordova.js

css

img

index.html

js

plugins

 

then I have the camera plugin inside the plugin folder..

                

Please blackberry dev.... what am i missing :smileysad:

 

Please use plain text.
New Developer
adebayooriyomi
Posts: 18
Registered: ‎01-09-2014
My Device: Blackberry 10
My Carrier: Virgin Mobile

Re: BlackBerry 10 Webworks 2.0 Camera api

@ Keab42... I know you might be thinking I'm not trying.. I'm trying so hard to get this to work... just not having any luck :smileysad:

see my folder structure image for more visual

http://oriyomiadebayo.com/webworks.jpg

thanks
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BlackBerry 10 Webworks 2.0 Camera api

Check out the thread here:
http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Cordova-3-2-0-Capture-Plugin-not...

The highlighted post builds on top of the sample earlier in the thread here:
http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Cordova-3-2-0-Capture-Plugin-not...

There were some issues with filesystem access but the thread does explain how to work around them. These only came up during the fileTransfer part though. For taking a picture and displaying the picture, you can simply prepend file:// to the returned imagePath and use that as an img src.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.