Accessing the camera phone with Adobe AIR for Android

Adobe AIR for Android can access some hardware features of smartphones. Among some of them we can mention the access to internet, read your phone’s status, access network, access the wifi, GPS, sensors, etc.. Adobe AIR can also access the camera device, and this can be done in two ways..

Adobe AIR is available for devices running Android from version 2.2 (Froyo)

we have two classes to access the camera with Adobe AIR for Android:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html
The first way to access the camera phone is using the Camera class, classical and already well known for our work in web and desktop environment. Before you can use the method Camera.isSupported, and using cameras to catch the Camera.getCamera().

Usually this class is also used to send the stream from your camera to the Flash Media Server(together with the NetStream class) and transmit to web, desktop or mobile. Here’s an example usage:
[ACTIONSCRIPT3]
var camera:Camera = Camera.getCamera();
if (camera != null)
{
video = new Video(camera.width * 2, camera.height * 2);
video.attachCamera(camera);
addChild(video);
}
else
{
trace(“You need a camera.”);
}
[/ACTIONSCRIPT3]
In getCamera, if not passed any parameters, access the device’s main camera, you can access a camera with the index specifies it as a string:
[ACTIONSCRIPT3]
var arrCamera:Array = Camera.names;// todas as câmeras como array
var camera:Camera = Câmera.getCamera(“1”);//acessando a câmera de indece 1
[/ACTIONSCRIPT3]

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraUI.html
CameraUI is a new class unique to Adobe AIR for Mobile Devices, allowing you to capture an image or video application standard camera phone. The image or video is available on the object MediaEvent. Here’s an example usage:
[ACTIONSCRIPT3]
var deviceCameraApp:CameraUI = new CameraUI();
var imageLoader:Loader;

deviceCameraApp.addEventListener( MediaEvent.COMPLETE, imageCaptured );
deviceCameraApp.addEventListener( Event.CANCEL, captureCanceled );
deviceCameraApp.addEventListener( ErrorEvent.ERROR, cameraError );
deviceCameraApp.launch( MediaType.IMAGE );

function imageCaptured( event:MediaEvent ):void
{
trace( “Media captured…” );

var imagePromise:MediaPromise = event.data;

if( imagePromise.isAsync )
{
trace( “Asynchronous media promise.” );
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );

imageLoader.loadFilePromise( imagePromise );
}
else
{
trace( “Synchronous media promise.” );
imageLoader.loadFilePromise( imagePromise );
showMedia( imageLoader );
}
}

function captureCanceled( event:Event ):void
{
trace( “Media capture canceled.” );
NativeApplication.nativeApplication.exit();
}

function asyncImageLoaded( event:Event ):void
{
trace( “Media loaded in memory.” );
showMedia( imageLoader );
}

function showMedia( loader:Loader ):void
{
this.addChild( loader );
}

function cameraError( error:ErrorEvent ):void
{
trace( “Error:” + error.text );
NativeApplication.nativeApplication.exit();
}
[/ACTIONSCRIPT3]

One last detail to work on the smartphone, it is necessary to set the permission for the application can access the camera on Android. This is done in the xml configuration of Adobe AIR:
[XML]

]]>

[/XML]

Was this article helpful? feel free to make a donation and help keep the blog in the air
Adobe AIR, Android, Flash , ,

5 comments


  1. Pingback: Accessing the camera phone with Adobe AIR for Android | Leonardo … | camera

Leave a Reply