Craig
Craig

Reputation: 1

How to get the camera to work with Blackberry Webworks

I am fairly new to webworks. I am trying to get the camera api to work and I keep getting the error:

Error in supported: TypeError: 'undefined' is not an object (evaluating 'blackberry.media.camera')

The page I am trying to use is on a hosted server. The code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<script language="javascript" type="text/JavaScript" >
function takePicture() {
try {
blackberry.media.camera.takePicture(successCB, closedCB, errorCB);
} catch(e) {
alert("Error in supported: " + e);
}
}
function successCB(filePath) { 
document.getElementById("path").innerHTML = filePath;

//alert("Succeed: " + filePath);
}
function closedCB() {
// alert("Camera closed event");
}
function errorCB(e) {
alert("Error occured: " + e);
}
</script>
<title>Camera Test Widget</title>
</head>
<body >
<p>Test the Camera by pressing the button below</p>
<b><a href="#" onclick="takePicture();">Take a Picture</a></b>
<div id="path"></div>
</body>
</html>

And my config.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" 
xmlns:rim="http://www.blackberry.com/ns/widgets" 
version="1.0.0.0" rim:header="WebWorks Sample">
<access uri="http://www.flyloops.net/" subdomains="true">
<feature id="blackberry.app.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
</access>
<name>Flyloops.net</name>
<description>This is a sample application.</description>
<content src="index.html"/>
</widget>

The page is hosted at: http://www.flyloops.net/mobile/bb/camera.html

I have been tearing my hair out for the past 3 hours...any help would be greatly appreciated.

Upvotes: 0

Views: 617

Answers (2)

Adam Stanley
Adam Stanley

Reputation: 1885

If using PlayBook, make sure to have the correct element(s) defined https://developer.blackberry.com/html5/apis/blackberry.media.camera.html

otherwise, if you are trying to access the blackberry.media.camera API from a remote website, then you need to white list that correctly in config.xml like this:

<access uri="http://www.flyloops.net/" subdomains="true">
   <feature id="blackberry.media.camera" />
</access>

Upvotes: 1

Naveenan
Naveenan

Reputation: 121

What device are you running? The code seems fine and it should work. You can get the eventlogs from the device and see what exceptions are being thrown.

Thanks

Naveen M

Upvotes: 0

Related Questions