With the release of the BlackBerry® Native SDK Beta 2 comes the Cascades™ Camera API. If you want to see it in action, check out the spiffy Photobomber sample app available in the BlackBerry Jam Zone and on GitHub. You can just import it, compile it, install it on your BlackBerry® 10 Dev Alpha and go.
However, there are a couple of set-up gotchas in the current beta you are going to run into if you are just trying to add Camera functionality to your own app. Luckily, they are pretty simple to get past, especially with me here telling you exactly what to do! Let’s quickly run through them.
1. QML Imports
In your QML file, right underneath the default:
import bb.cascades 1.0you want to also add:
import bb.cascades.multimedia 1.0.This will let the QML editor know about the camera components so it doesn’t complain at you.
2. Include the Camera headers
This is pretty standard C++ stuff, but don’t forget to also import the headers into your C++ code. In your default app.cpp you will want to import at least this:
#include You may also end up needing a few others if you are doing more involved camera work in C++, like this:
3. Register the Camera in C++
In your default app.cpp file, right before the call to:
QmlDocument *qml = QmlDocument::create("main.qml");Add:
bb::cascades::multimedia::Camera::registerQmlTypes ();If you don’t do this, the Camera components won’t actually get loaded and you’ll get an error. This is also why you imported the Camera header file, if you are doing the rest of the camera work in QML.
4. Link to the Multimedia Libraries
Right now the linker isn’t quite set up properly to connect your app to some of the new libraries added in R6. For now, you’ll want to manually open the .pro file and add the following line:
LIBS += -lcamapi -lscreen -lbbsystem -lbbcascadesmultimedia –lzxingNot all of those are strictly necessary (for example, the zxing library will only be helpful if you want to connect to ZXing to do some custom barcode scanning. We’ll talk about how to do that in a future blog post), but it’s not going to hurt, and the names of the libraries are not terribly discoverable on your own.
You’ll note there is no LIBS line by default in your .pro file. I like to add mine below the CONFIG line, though I’m not sure it really matters.
That’s it, you’re all set up! Now you can use the Camera API to your heart’s content. If doing so results in your app taking a lot of pictures, don’t forget you can use the Invoke Framework to let your users easily share them. It’s a snap.