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

Native Development

Reply
Regular Contributor
Posts: 55
Registered: ‎10-31-2012
My Device: Blackberry 10 Dev Alpha Simulator - VMware
My Carrier: (none)
Accepted Solution

"The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

[ Edited ]

I am using Blackberry 10 Cascades (C++, QT & QML), and I am trying to invoke the camera on a physical Blackberry Z 10, but when I do so I am getting the error, "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades.", but I can't find any other apps that are using the camera as opened, including the camera. Is there a way I can check all apps that are running, including hidden ones? And close all other running apps (hidden or not - both manually & programatically)?

My code to start the camera looks like this:

InvokeManager manager;
InvokeRequest request;
request.setTarget("sys.camera.card");
request.setAction("bb.action.CAPTURE");
request.setMimeType("image/jpeg");
InvokeTargetReply* reply = manager.invoke(request);

Or is/are there some other solution(s) to this problem?

Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

Why are you looking to invoke the Camera? You can use it in your own app via QML or C++.

 

Code example for qml:

 

import bb.cascades 1.0
import bb.multimedia 1.0
import bb.cascades.multimedia 1.0
 
Page {
    actions: [
        ActionItem {
            title: "Flash Mode: Off"
            ActionBar.placement: ActionBarPlacement.InOverflow
            onTriggered: {
                camera1.getSettings(settings);
                settings.flashMode = CameraFlashMode.Off;
                camera1.applySettings(settings);
            }
        },
        ActionItem {
            title: "Flash Mode: On"
            ActionBar.placement: ActionBarPlacement.InOverflow
            onTriggered: {
                camera1.getSettings(settings);
                settings.flashMode = CameraFlashMode.On;
                camera1.applySettings(settings);
            }
        },
        ActionItem {
            title: "Flash Mode: Auto"
            ActionBar.placement: ActionBarPlacement.InOverflow
            onTriggered: {
                camera1.getSettings(settings);
                settings.flashMode = CameraFlashMode.Auto;
                camera1.applySettings(settings);
            }
        },
        ActionItem {
            title: "Flash Mode: Light"
            ActionBar.placement: ActionBarPlacement.InOverflow
            onTriggered: {
                camera1.getSettings(settings);
                settings.flashMode = CameraFlashMode.Light;
                camera1.applySettings(settings);
            }
        }
    ]
 
    // The root container.
    content: Container {
        id: cntrRoot
        // The Camera control.
        Camera {
            id: camera1
            property bool photoBeingTaken;
            property variant supCameras;
            attachedObjects: [
                // Required to play the shutter sound.
                SystemSound {
                    id: shutterSound
                    sound: SystemSound.CameraShutterEvent
                },
 
                CameraSettings {
                    id: settings
                }
            ]
 
            // Find a supported camera unit and open the camera.
            onCreationCompleted: {
                supCameras = camera1.supportedCameras;
 
                // Check to see if your app has access to the camera.
                if (supCameras.length == 0 ||
                    supCameras[0] == CameraUnit.None)
                {
                    // Report: "No camera units are accessible."
                    console.log("No camera units are accessible");
                }
                else if (supCameras[0] == CameraUnit.Rear ||
                           supCameras[1] == CameraUnit.Rear)
                {
                    console.log("The rear camera unit is accessible.");
                    camera1.open(CameraUnit.Rear);
                }
                else if (supCameras[0] == CameraUnit.Front ||
                           supCameras[1] == CameraUnit.Front)
                {
                    console.log("The front camera unit is accessible.");
                    camera1.open(CameraUnit.Front);
                }
                else
                {
                    // Report unknown error.
                }
            }
 
            onTouch: {
                if (photoBeingTaken == false) {
                    photoBeingTaken = true;
                    // Take a photo, and automatically
                    // save it to the file system.
                    camera1.capturePhoto();
                }
            }
 
            onCameraOpened: {
                // When the camera is open, start the viewfinder.
                camera1.startViewfinder();
            }
 
            onViewfinderStarted: {
                photoBeingTaken = false;
            }
 
            // In many countries the law requires that a shutter-sound be played
            // when an app is taking pictures. Further, if you're planning on
            // submitting your app to BlackBerry World, then it's required that
            // it must play the shutter sound when taking photos.
 
            onShutterFired: {
                shutterSound.play();
            }
 
            onPhotoSaved: {
                photoBeingTaken = false;
            }
        } // End of Camera control.
    } // End of cntrRoot.
}

 

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Regular Contributor
Posts: 55
Registered: ‎10-31-2012
My Device: Blackberry 10 Dev Alpha Simulator - VMware
My Carrier: (none)

Re: "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

I have been trying to get this example to work - what I want is to be able to click a button and have the camera start.  I have been looking all over for an example on how to do this, and trying to use it myself, but none of it works.  Could someone show me a simple example, of to cause the camera to start after clicking a button.

Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

Sure, if you want it to start the viewfinder with a button instead of automatically, you can create a button or action item and have this code in it:

 

Button{
  onTouch:{
    supCameras = camera1.supportedCameras;
 
                // Check to see if your app has access to the camera.
                if (supCameras.length == 0 ||
                    supCameras[0] == CameraUnit.None)
                {
                    // Report: "No camera units are accessible."
                    console.log("No camera units are accessible");
                }
                else if (supCameras[0] == CameraUnit.Rear ||
                           supCameras[1] == CameraUnit.Rear)
                {
                    console.log("The rear camera unit is accessible.");
                    camera1.open(CameraUnit.Rear);
                }
                else if (supCameras[0] == CameraUnit.Front ||
                           supCameras[1] == CameraUnit.Front)
                {
                    console.log("The front camera unit is accessible.");
                    camera1.open(CameraUnit.Front);
                }
                else
                {
                    // Report unknown error.
                }
  }
}

Make sure camera1 and supCameras are declared for your entire qml file (ie in just under the Page{} line). No it'll callcamera1.open(CameraUnit) wheneer you press the button. There's an example app here, though it's done in c++, so you'll get the pick of which method you want to use!

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Regular Contributor
Posts: 55
Registered: ‎10-31-2012
My Device: Blackberry 10 Dev Alpha Simulator - VMware
My Carrier: (none)

Re: "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

Thankyou, I got the camera working.  But now, when I tap the camera to try to take a picture.  I get ""TypeError: Result of expression 'app.manipulatePhoto' [undefined] is not a function."

 

That error is in this function:

 

    onPhotoSaved: {
                    var fileName;
                    app.manipulatePhoto(fileName);                 // crashses on this line (app.maniputlatePhoto(fileName)
                    trace(fileName);
                    imageSheet.open();
                    imageSheet.previewPath = fileName;
                }
         }

 

I have tried to find a solution to this problem, but can't seem to on the internet

 

Regular Contributor
Posts: 55
Registered: ‎10-31-2012
My Device: Blackberry 10 Dev Alpha Simulator - VMware
My Carrier: (none)

Re: "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

Never mind about the last question, I realized that manipulatePhoto was a function coded in the photobomber, so I just put that same function in my app, and fixed that issue.

Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: "The camera is in use. Close any applications using it and try again. in Blackberry Z10 when invoking the camera in Blackberry 10 Cascades

Glad to hear it and I hope that the app works the way you want it now. And remember to mark the thread as solved at the solution!

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!