Search

 

September 2010
S M T W T F S
« Jul   Oct »
 1234
567891011
12131415161718
19202122232425
2627282930  

Tags

Archives


« | Main | »

AIR on Android: CameraRoll

By Rich Tretola | September 17, 2010
9,824 views

The flash.media.CaremaRoll class allows you to access the images stored on your Android devise. The process is clean and simple. This example shows how to browse the devise and load an image into your application. The key to this process (which is different than desktop AIR) are the MediaEvent and MediaPromise classes. Lets take a look at the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package
{
    import flash.display.Sprite;
    import flash.events.MediaEvent;
    import flash.events.MouseEvent;
    import flash.media.CameraRoll;
    import flash.media.MediaPromise;
   
    public class Cam extends Sprite
    {
       
        private var roll:CameraRoll;
       
        public function Cam() {
            roll = new CameraRoll();
            roll.addEventListener(MediaEvent.SELECT,imageSelected);
            //browseCameraBtn is a Button object which is on my Flash CS5 stage
            browseCameraBtn.addEventListener(MouseEvent.CLICK,browseCameraBtnClicked);
        }
         
        private function browseCameraBtnClicked(event:MouseEvent):void{        
            if(CameraRoll.supportsBrowseForImage){
                roll.browseForImage();         
            } else {
                mediaPath.text = "Browse for Image not supported";
            }
        }
       
        private function imageSelected(event:MediaEvent):void{
            var mp:MediaPromise = event.data;
            //mediaPath is a text object which is on my Flash CS5 stage
            mediaPath.text = mp.file.name + "\n" + mp.file.url;
            //loader is a flash.containers.UILoader which is on my Flash CS5 stage
            loader.source = mp.file.url;
        }
       
    }
}

One more thing that is required is the addition of the android permission to allow access to the Camera within the application config file.

1
2
3
4
5
6
7
8
9
<android>
    <manifestAdditions>
      <manifest>
        <data><![CDATA[
        <uses-permission android:name="android.permission.CAMERA" />
        ]]></data>
      </manifest>
    </manifestAdditions>
  </android>

The process is simple. Here is the order of events:

Screen Shot 1 shows the app is the default state:
camtest1

Screen Shot 2 shows the Nexus One’s image selector:

camtest2

Screen Shot 3 shows the app with the image name, path, and preview:
camtest3

Topics: ActionScript 3, Adobe AIR, android, mobile | 1 Comment »

One Response to “AIR on Android: CameraRoll”

  1. Tweets that mention AIR on Android: CameraRoll | EverythingFlex: Flex & AIR -- Topsy.com Says:
    September 17th, 2010 at 9:18 am

    [...] This post was mentioned on Twitter by Rich Tretola, Rich Internet Apps. Rich Internet Apps said: NICE! AIR on Android: CameraRoll http://bit.ly/cpIXo9 /via @richtretola [...]

Comments