Workaround for Adobe AIR saving 2 duplicate copies of image using CameraUI

Assuming that you have similar code snippet for capturing image on Android using Camera UI as given below, here is a way to beat a very irritating bug in Adobe AIR for android. Just follow the steps mentioned and perhaps you can rid yourself of this issue completely.

 

 

var cameraUI:CameraUI;

function capture():void
{
if( CameraUI.isSupported )
{
cameraUI = new CameraUI();
cameraUI.addEventListener( MediaEvent.COMPLETE, imageSelected );
cameraUI.addEventListener( ErrorEvent.ERROR, mediaError );
cameraUI.launch( MediaType.IMAGE );
}
else
{
trace( "CameraUI is not supported.");
}
}

private function mediaError(E:ErrorEvent):void
{
trace("AN ERROR OCCURED");
}

private function imageSelected( event:MediaEvent ):void
{

trace( event.data.file.url);
cameraUI.removeEventListener( MediaEvent.COMPLETE, imageSelected );
cameraUI.removeEventListener( ErrorEvent.ERROR, mediaError );
cameraUI = null;

}

 

Why do you get double images ?

It seems that the CameraUI and Adobe AIR both save one copy each of the image. On your Android device, The CameraUI usually saves to CameraRoll standard folder, where as Adobe AIR saves it to a different folder:

CameraUI saves to – /mnt/sdcard/DCIM/100MEDIA

Adobe AIR saves to – /mnt/sdcard/DCIM/Camera

So when you go to CameraRoll you see 2 images because android will scan for all newly taken images.

 

What can you do ?

What i suggest is that after you have got the event.data.file object using MediaEvent, determine the last modified time of this file.

Next look for any file whose Last Modified DateTime is exactly the same as event.data.file. (You can do this by listing the CameraUI  directory and filtering the files by Last Modified DateTime to get the one you are looking for)

Yes it may sound tedious but its important because the filenames used for both images are different. So you need to either use Last Modified DateTime or Some sort of  file checksum technique.

Once you have located the duplicate file inside CameraUI  directory delete it instantly.

If this bug is really critical to your project,  you can try this method. If not then live with it 🙂 and tell your customer we will fix it when adobe does. 🙂

 

Note: I havent had time to personally cook up a demo apk file, but i am guessing this will work.

2 Comments - Leave a comment
  1. Paul says:

    Hi Rajdeep.
    Thanks for this. I am playing around with cameraUI at the moment so will try it. Do you know how to browse cameraroll for video. I think standard cameraroll cant do this. Thanks

    Paul

  2. Kodiak says:

    Hi,
    I experience the same issue as you. I tried your solution but it seems that the 100MEDIA picture is not created at the exact same time as the other one (event.data.file). It’s tagged generaly one second before. So I have to rely on the file size and check a reasonnable time interval (3 seconds).
    My new problem is that deleteFile does not work. It empties the file and leaves a 0 byte file…

Leave a Reply

Your email address will not be published. Required fields are marked *

*