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

Adobe AIR Development

Reply
Contributor
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel

How to Open Camera in playbook

Hi to every one,

I am developing an app based on images, in that app, i need camera option ,

I tried several ways to open it but can possible,

can any one help me to solve this

i am waitng

here is my code

var cam:Camera = Camera.getCamera(); // after this line cam still null
var vid:Video = new Video();
vid.attachCamera(cam); 
addChild(vid);

 

thanks in advnce

Developer
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: How to Open Camera in playbook

[ Edited ]

You  may need to specify which camera  in the call to Camera.getCamera. You can find which cameras are available in the Camera.names array.

 

Using the camera via this method would be limited to the screen resolution. For higher res, use the CameraUI API.

 

 

Remember to request camera permission in your bar-descriptor.xml too.

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: How to Open Camera in playbook

I have had success using the following code:

function takePhoto():void {
	if( CameraUI.isSupported ){
	     /** Launch Camera */
	
	     cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected);
	     cameraUI.addEventListener(Event.CANCEL, imageCancelled);
	     cameraUI.addEventListener(ErrorEvent.ERROR, imageError);
	     cameraUI.launch( MediaType.IMAGE );
        } else {
	     /** handle CameraUI Not being supported */
        }
}	

 This should launch the camera on the PlayBook.

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Contributor
Posts: 42
Registered: ‎08-30-2012
My Device: PlayBook
My Carrier: Aircel

Re: How to Open Camera in playbook

Thanks everyone camaraUI class is also not supporting my needs

Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
My Carrier: Rogers

Re: How to Open Camera in playbook

If you could elaborate with an example of your needs someone may be able to provide better help...

 

If you feel you'd be giving your idea away use a vague example to explain your needs, although I doubt there are many trolls here looking to steal ideas.

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to Open Camera in playbook

[ Edited ]

Invocation makes this easy too:

/////////////////////////////////////////////////////////////
private function TakePhoto( event : Event ) : void
{
	var request : InvokeRequest = new InvokeRequest();
	request.action = 'bb.action.CAPTURE';
	request.target = 'sys.camera.card';
	request.data = new ByteArray();
	request.data.writeUTF( 'photo' );
			
	InvokeManager.invokeManager.addEventListener(CardCloseEvent.CARD_CLOSED, CardClosed );
	InvokeManager.invokeManager.invoke( request );
}
		
/////////////////////////////////////////////////////////////
private function CardClosed( event : CardCloseEvent ) : void
{
	trace( 'card closed ' + event.reason + ' ' + event.data );
	InvokeManager.invokeManager.removeEventListener( CardCloseEvent.CARD_CLOSED, CardClosed );
			
	if( event.reason == 'save' && event.data != '' )
	{
		this.image.setImage( 'file://' + event.data );
	}
}

 

Developer
Posts: 306
Registered: ‎03-01-2011
My Device: Playbook (sim)
My Carrier: Base

Re: How to Open Camera in playbook

I have a question just to clearify this a bit. Does this code capture an image within AIR using the camera without opening the camera app and saves it as a file?
..................................................................................................................................................................................................................

My App: Peg Solitaire

Need a designer? Drop me a line
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to Open Camera in playbook

It slides the camera from the bottom as a card. The user does not know that it is opening up the camera app. Upon completion, you get the event callback. The photo is stored to the device and you get a path to that file. I know with the AIR camera, getting the last photo taken takes a little work. The invocation method (for me) was a lot easier then the AIR way to do it.
Developer
Posts: 306
Registered: ‎03-01-2011
My Device: Playbook (sim)
My Carrier: Base

Re: How to Open Camera in playbook

this seems to be exactly what I need. Can I close the camera app with the invocation framework after use? and is it possible to take more than one photo?
..................................................................................................................................................................................................................

My App: Peg Solitaire

Need a designer? Drop me a line
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to Open Camera in playbook

Once you take a picture or cancel from taking a picture the card goes away and you receive the callback. In that case, I guess you would need to redisplay the card when the callback is received with a valid image being taken. If you need to take several pictures at "one time", then the invocation might not be best for you. You might be able to put in an enhancement request to have an option with invocating the camera, to leave it up until the app requests it to go away or until the user cancels out of the camera.