Code Snippet: Using Air to Load An Image Using the CameraRoll and MediaPromise Classes

Using Air for Android you can use the built in Android gallery to browse for and load an image into your application.

var cameraRoll:CameraRoll;
if (CameraRoll.supportsBrowseForImage)
{
    cameraRoll = new CameraRoll();
    cameraRoll.addEventListener(MediaEvent.SELECT, onImageselected);
    cameraRoll.browseForImage();
}

function onImageselected(e:MediaEvent):void
{
    var data:MediaPromise = e.data;
    trace("file type: " + data.mediaType);
    trace("file name: " + data.file.name);
    trace("file url: " + data.file.url);
           
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, addImage);
    loader.load(new URLRequest(data.file.url));
}

function addImage(e:Event):void
{
    addChild(e.target.content);
}

Upon testing it seems you do not need to add the android.permission.CAMERA permission to your applications XML descriptor file.

Posted in Air for Android, Code Snippets | Tagged , , , , | Leave a comment

Code Snippet: Using Air to Access The Microphone on your Android Device

Using Air for Android to access the Microphone (almost exactly the same way as accessing the camera) on your device :

var mic:Microphone;
           
if(Microphone.isSupported)
{
    mic = Microphone.getMicrophone();
    mic.rate = 44;
    mic.addEventListener(SampleDataEvent.SAMPLE_DATA, onMicDataRecieved);
}

function onMicDataRecieved(e:SampleDataEvent):void
{
    trace("mic level: " + mic.activityLevel);
}

You also need to give your app permission to use the microphone by editing the applications XML file to include the following under the root (<application>) element:

<android>
    <manifestAdditions>
      <![CDATA[<manifest>
       <uses-permission android:name="android.permission.RECORD_AUDIO"/>
       </manifest>]]>
    </manifestAdditions>
  </android>
Posted in Air for Android, Code Snippets | Tagged , , , | Leave a comment

Code Snippet: Using Air to Access The Camera on your Android Device

Using Adobe Air for Android to access the camera on your device.

import flash.media.Camera;

var video:Video = new Video(320, 240);
var camera:Camera = Camera.getCamera();
camera.setMode(video.width, video.height, 25);
video.attachCamera(camera);
addChild(video);

You also need to give your app permission to use the camera by editing the applications XML file to include the following under the root (<application>) element:

<android>
    <manifestAdditions>
      <![CDATA[<manifest>
       <uses-permission android:name="android.permission.CAMERA"/>
       </manifest>]]>
    </manifestAdditions>
  </android>
Posted in Air for Android, Code Snippets | Tagged , , , | Leave a comment

Code Snippet: Using Air to Access The Accelerometer on your Android Device

Using Adobe Air for Android to test whether your device has an Accelerometer, and how to receive the current values from it:

import flash.events.AccelerometerEvent;
import flash.sensors.Accelerometer;

var _accelerometer:Accelerometer;

if (Accelerometer.isSupported)
{
    _accelerometer = new Accelerometer();
    _accelerometer.addEventListener(AccelerometerEvent.UPDATE, update);
    _accelerometer.setRequestedUpdateInterval(100);
}
//else not supported

function update(e:AccelerometerEvent):void
{
    trace("x: " + e.accelerationX);
    trace("y: " + e.accelerationY);
    trace("z: " + e.accelerationZ);
}
Posted in Air for Android, Code Snippets | Tagged , , , | Leave a comment

How To: Install the Android SDK and Compile Your Air Application Part 1

This 2 part ‘how to’ will discuss setting up the Android SDK on a Windows platform, and use Flash CS5 to publish our Air app to an Android emulator (or your device).

First, a brief overview of the steps involved:

  1. Download and install the Android SDK and setup an Android emulator for testing (Part 1)
  2. Download and install the Air for Android Runtime and the Flash CS5 Android extension (Part 2)
  3. Use Flash CS5 to create and publish the application to the emulator or your device (Part 2)

Part 1.

First, we need to head over to http://developer.android.com/sdk/to download the SDK. Once there, click on the SDK download link for the Windows platform.

Once the download is complete, we need to extract the contents of the zip file to a permanent, safe location. You can choose whatever directory you like, but for simples sake i’m going to create a directory called android on the root of my c:\ drive (c:\android) to store the SDK. Using Winrar (or your own favourite zip utility) to open the downloaded zip file, we can drag and drop the android-sdk-windows directory from Winrar straight into the c:\android directory to extract the contents.

Once the extraction is complete, close Winrar and browse to the android-sdk-windows directory (mine would be c:\android\android-sdk-windows) and double click on the SDK Manager.exe file within.

As Adobe Air for Android requires Android 2.2 (Froyo) to run, we are only going to select the 2.2 archive to install – you can safely de-select the older Android platform archives from the list (by double-clicking each one until the icon turns to a red cross) like so:

When you click install the SDK Manager will download the rest of the required files, including any documentation / examples you marked for install. If you have your device to hand and wont be using an emulator, you should select the ‘Usb Driver package’ as well.

Once complete, select the ‘Virtual Devices’ item in the list in the SDK Manager and click ‘New’. In the Create AVD (Android Virtual Device) window, type a name for your emulator, e.g. ‘Froyo_Emulator’ and (the important bit) select Android 2.2 as the target.

You may also specify a virtual SD-Card that the emulator can access if you wish by inserting a value of your choice into the ‘Size’ text box. Under ‘Skin’ I changed the ‘Built in’ option from Default (HVGA) to WVGA800 which will set the screen resolution of the emulator to 480×800 (the same as the HTC Desire and the Nexus One).

Click the ‘Create AVD’ button once done to save the emulator, which will now appear in the list of your currently installed emulators (you can have more than one emulator which is handy if you want to test native applications on older versions of Android or to test your app on different screen resolutions).

Select your newly created emulator from the list and hit start, and then launch. The first launch of your new emulator may take longer while the operating system configures itself. Take the opportunity to browse around the OS and get used to the feel of it. I do find the Android emulator can be quite slow and laggy.

Part 2 coming soon…

Posted in Air for Android, Applications, Tutorials | Tagged , , , , , | Leave a comment

Android Apps on TV

Google TV LogoWatch out world the Google TV platform is coming! No company has yet succeed in truly uniting the electronic device we probably use the most with the internet in a true web TV format. Many have tried over the years the most notable recent flop being Apples miserable TV box. It would seem a risky business but then if anybody could pull of this marriage it would have to be the internet might of Google. If Steve Jobs life couldn’t get any worse Google is working with Apples rival Sony to produce the first devices and will be including flash player and Android App support.

Google are inviting developers to sign up for information here.

Posted in Android General, Android Vs Apple | Tagged , , , | Leave a comment

AIRonAndroid Browser Application

AIRonAndroid AppAIRonAndroid Browser is an Air API demo application by Rich Tretola. The application demonstrations include the Accelerometer, Camera, Geolocation, Multitouch, StageOrientation, and KeyboardEvents.

Get the app here

Posted in Applications, Utilities | Tagged , , , , , , , , | Leave a comment

Publishing AIR for Android Applications

Lee Brimelow proves just how easy it is to build and publish an AIR Android application for the market in around 6 minutes.

View the tutorial here

Posted in Air for Android, Tutorials | Tagged , , , | Leave a comment