Here is some sample code:
Java Example
// Request a camera snapshot and store the file in the location specified in _path
protected void startCameraActivity() { File file = new File( _path ); Uri outputFileUri = Uri.fromFile( file ); Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE ); intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri ); startActivityForResult( intent, 0 ); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i( "MakeMachine", "resultCode: " + resultCode ); switch( resultCode ) { case 0: Log.i( "Say Cheese Snapshot", "User cancelled" ); break; case -1: onPhotoTaken(); break; } }
FlashBuilder 4.5 Example
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:s="library://ns.adobe.com/flex/spark"applicationComplete="application1_applicationCompleteHandler(event)"><fx:Script><![CDATA[import mx.events.FlexEvent;private var camera:CameraUI;protected function application1_applicationCompleteHandler(event:FlexEvent):void {if (CameraUI.isSupported){camera = new CameraUI();camera.addEventListener(MediaEvent.COMPLETE, onComplete);camera.addEventListener(ErrorEvent.ERROR, onError);status.text="CameraUI supported";} else {status.text="CameraUI NOT supported";}}private function captureImage(event:MouseEvent):void {camera.launch(MediaType.IMAGE);}private function onError(event:ErrorEvent):void {trace("error has occurred");}private function onComplete(event:MediaEvent):void {var mediaPromise:MediaPromise = event.data;status.text = mediaPromise.file.url;image.source = mediaPromise.file.url;}]]></fx:Script><fx:Declarations><!-- Place non-visual elements (e.g., services, value objects) here --></fx:Declarations><s:Label id="status" text="Click Take a Picture button" top="10" width="100%" textAlign="center"/><s:Button width="300" height="60" label="TAKE A PICTURE" click="captureImage(event)"horizontalCenter="0" enabled="{CameraUI.isSupported}"top="80"/><s:Image id="image" width="230" height="350" horizontalCenter="0" top="170"/></s:Application>