Tuesday, January 17, 2012

ViewFlipper in Android

ViewFlipper is used to do animation when switching between views. There are lot of options for doing animations between views like ViewAnimator, LayoutAnimationController, applying animation to the view itself. But I feel ViewFlipper is the better option for doing animation for switching views.

In this I am controlling the switching between views using user interaction(Button click). We can set duration also for switching between views.

The complete code for showing ViewFlipper is,

public class ShowFlipper extends Activity {

 ViewFlipper flipper;
 Button button1;
 Button button2;
 LinearLayout l1;
 LinearLayout l2;
 TextView tv1, tv2, tv3, tv4, tv5, tv6;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);

  flipper = new ViewFlipper(this);
  l1 = new LinearLayout(this);
  l2 = new LinearLayout(this);
  button1 = new Button(this);
  button2 = new Button(this);
  button1.setText("Button 1");
  button2.setText("Button 2");

  l1.setOrientation(LinearLayout.VERTICAL);
  l2.setOrientation(LinearLayout.VERTICAL);
  tv1 = new TextView(this);
  tv2 = new TextView(this);
  tv3 = new TextView(this);
  tv4 = new TextView(this);
  tv5 = new TextView(this);
  tv6 = new TextView(this);
  tv1.setText("text view 1");
  tv2.setText("text view 2");
  tv3.setText("text view 3");
  tv4.setText("text view 4");
  tv5.setText("text view 5");
  tv6.setText("text view 6");
  l1.addView(tv1, params);
  l1.addView(tv2, params);
  l1.addView(tv3, params);
  l1.addView(button1, params);
  l2.addView(tv4, params);
  l2.addView(tv5, params);
  l2.addView(tv6, params);
  l2.addView(button2, params);

  flipper.addView(l1);
  flipper.addView(l2);

  button1.setOnClickListener(new View.OnClickListener() {
   public void onClick(View view) {
    flipper.setInAnimation(inFromRightAnimation());
    flipper.setOutAnimation(outToLeftAnimation());
    flipper.showNext();
   }
  });

  button2.setOnClickListener(new View.OnClickListener() {
   public void onClick(View view) {
    flipper.setInAnimation(inFromLeftAnimation());
    flipper.setOutAnimation(outToRightAnimation());
    flipper.showPrevious();
   }
  });
  setContentView(flipper);
 }

 private Animation inFromRightAnimation() {
  Animation inFromRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, +1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
  inFromRight.setDuration(500);
  inFromRight.setInterpolator(new AccelerateInterpolator());
  return inFromRight;
 }

 private Animation outToLeftAnimation() {
  Animation outtoLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, -1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
  outtoLeft.setDuration(500);
  outtoLeft.setInterpolator(new AccelerateInterpolator());
  return outtoLeft;
 }

 private Animation inFromLeftAnimation() {
  Animation inFromLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, -1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
  inFromLeft.setDuration(500);
  inFromLeft.setInterpolator(new AccelerateInterpolator());
  return inFromLeft;
 }

 private Animation outToRightAnimation() {
  Animation outtoRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, +1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
  outtoRight.setDuration(500);
  outtoRight.setInterpolator(new AccelerateInterpolator());
  return outtoRight;
 }
}


You can download the full source code from here

Wednesday, January 11, 2012

Android sample App : Drag And Drop Image using Touch


 TouchActivity.java
package com.example.Touch;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.AbsoluteLayout.LayoutParams;
public class TouchActivity extends Activity{
/** Called when the activity is first created. */
ImageView img=null;
AbsoluteLayout aLayout;
int status=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aLayout= (AbsoluteLayout)findViewById(R.id.absLayout);
img=(ImageView)findViewById(R.id.imageView);
//sa.setFillAfter(true);
img.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
status=1;
Log.i(“ImageStatus”,”"+status);
//img.setBackgroundColor(Color.WHITE);
return false;
}
});
aLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.i(“touch”,”"+event);
if(status==1) // any event from down and move
{
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,(int)event.getX()-img.getWidth()/2,(int)event.getY()-img.getHeight()/2);
img.setLayoutParams(lp);
}
if(event.getAction()==MotionEvent.ACTION_UP){
status=0;
img.setBackgroundColor(Color.TRANSPARENT);
}
return true;
}
});
}
}
——————————————————————————————————————————————-
Main.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:id=”@+id/LLayout”
>
<AbsoluteLayout
android:id=”@+id/absLayout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<ImageView android:layout_height=”wrap_content” android:id=”@+id/imageView” android:layout_width=”wrap_content” android:src=”@drawable/icon”></ImageView>
</AbsoluteLayout>
</LinearLayout>



Drag ANd Drop Image
Drag ANd Drop Image




Blocking Incoming call - Android

Step 1:
Create Broadcast receiver class for incoming call

package com.javaorigin.android.sample;

import java.lang.reflect.Method;

import com.android.internal.telephony.ITelephony;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent
import android.telephony.TelephonyManager;
import android.util.Log;

public class PhoneCallReceiver extends BroadcastReceiver {
 Context context = null;
 private static final String TAG = "Phone call";
 private ITelephony telephonyService;

 @Override
 public void onReceive(Context context, Intent intent) {
  Log.v(TAG, "Receving....");
  TelephonyManager telephony = (TelephonyManager) 
  context.getSystemService(Context.TELEPHONY_SERVICE);  
  try {
   Class c = Class.forName(telephony.getClass().getName());
   Method m = c.getDeclaredMethod("getITelephony");
   m.setAccessible(true);
   telephonyService = (ITelephony) m.invoke(telephony);
   telephonyService.silenceRinger();
   telephonyService.endCall();
  } catch (Exception e) {
   e.printStackTrace();
  }
  
 }

 
}


Step 2:
Create IDL interface for getting core Telephony service 
package name must be com.android.internal.telephony

FileName : ITelephony.aidl
  package com.android.internal.telephony;

  interface ITelephony {

   
    boolean endCall();

  
    void answerRingingCall();

   
    void silenceRinger();

  }


Step 3:
AndroidManifest.xml configuration
  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.javaorigin.android.sample"
      android:versionCode="1"
      android:versionName="1.0">  
    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <receiver  android:name=".PhoneCallReceiver">
            <intent-filter  android:priority="100" >
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

    </application>
    <uses-sdk android:minSdkVersion="5" />
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-sdk android:minSdkVersion="8" />

</manifest>

Android Sensor


Android Sensor
This tutorial describes how to use the Androids Sensor manager. It currently demonstrates the accelerometer. The tutorial is based on Eclipse 3.6, Java 1.6 and Android 2.3.3 (Gingerbread).

1. Android Sensors

Android supports several sensors via the SensorManager, for example the accelerometer. Unfortunately you cannot test the accelerometer on the Android emulator.
Once you get the ServiceManager via getSystemService(SENSOR_SERVICE) you can register a "SensorEventListener" to it. To avoid the unnecessary usage of battery you register your listener in the onResume method and de-register on the onPause method.

2. Example

Create a new Android project "de.vogella.android.sensor" with the activity "SensorTest".
Change your layout "main.xml" to the following.

   
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <TextView android:id="@+id/textView" android:layout_width="match_parent"
  android:layout_height="match_parent" android:text="Shake to get a toast and to switch color" />
</LinearLayout>

  

Change the coding of your activity Activity.

   
package de.vogella.android.sensor;

import android.app.Activity;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class SensorTest extends Activity implements SensorEventListener {
 private SensorManager sensorManager;
 private boolean color = false; 
 private View view;
 private long lastUpdate;

 
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.main); view = findViewById(R.id.textView); view.setBackgroundColor(Color.GREEN); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); lastUpdate = System.currentTimeMillis(); } @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { float[] values = event.values; // Movement float x = values[0]; float y = values[1]; float z = values[2]; float accelationSquareRoot = (x * x + y * y + z * z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH); long actualTime = System.currentTimeMillis(); if (accelationSquareRoot >= 2) // { if (actualTime - lastUpdate < 200) { return; } lastUpdate = actualTime; Toast.makeText(this, "Device was shuffed", Toast.LENGTH_SHORT) .show(); if (color) { view.setBackgroundColor(Color.GREEN); } else { view.setBackgroundColor(Color.RED); } color = !color; } } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub } @Override protected void onResume() { super.onResume(); // register this class as a listener for the orientation and // accelerometer sensors sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); } @Override protected void onPause() { // unregister listener sensorManager.unregisterListener(this); super.onStop(); } }

3. Thank you



Please help me to support this article:  

Saturday, January 7, 2012

Google AdMob Ads Android Fundamentals


  1. Overview
  2. Requirements
  3. Incorporating the SDK
    1. Adding the SDK JAR
    2. AdActivity
    3. Permissions
  4. Adding a com.google.ads.AdView
  5. The Result
  6. What's Next?

Overview

Google AdMob Ads banners use a small portion of the screen to entice users to "click through" to a richer, full-screen experience such as a website or app store page.
To display banners in your Android app, simply incorporate the SDK into your Eclipse project and add a com.google.ads.AdView to your UI.

Requirements

The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).

Incorporating the SDK

Incorporating Google AdMob Ads into your app is a three step process:
  1. Add the SDK JAR to your Eclipse project.
  2. Declare com.google.ads.AdActivity in AndroidManifest.xml.
  3. Set up required network permissions in the manifest.

Adding the SDK JAR

The decompressed SDK consists of a JAR, a javadoc folder and a README.
1. Right click on your app project in Eclipse and choose Properties.
2. Select Java Build Path and the Libraries tab. Then click Add External JARs... to add the Google AdMob Ads JAR.

com.google.ads.AdActivity

The AdMob Ads SDK requires that com.google.ads.AdActivity be declared in your app's AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name"
               android:debuggable="true">
    <activity android:label="@string/app_name" android:name="BannerExample">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
  </application>
</manifest>

Permissions

Making ad requests requires the networking permissions INTERNET and ACCESS_NETWORK_STATE, so these must also be declared in the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
  <application android:icon="@drawable/icon" android:label="@string/app_name"
               android:debuggable="true">
    <activity android:label="@string/app_name" android:name="BannerExample">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
  </application>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
You should now be able to rebuild your project without any errors.

Adding a com.google.ads.AdView

Android apps are composed of View objects, Java instances the user sees as text areas, buttons and other controls. AdView is simply another View subclass displaying small HTML5 ads that respond to user touch.
Like any View, an AdView may be created either purely in code or largely in XML.
The five lines of code it takes to add a banner:
  • Import com.google.ads.*
  • Declare an AdView instance
  • Create it, specifying a unit ID—your AdMob publisher ID
  • Add the view to the UI
  • Load it with an ad
The easiest place to do all this is in your app’s Activity.
import com.google.ads.*;
public class BannerExample extends Activity {
  private AdView adView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the adView
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);

    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());
  }

  @Override
  public void onDestroy() {
    adView.destroy();
    super.onDestroy();
  }
}
Warning: Make sure you're in test mode during development to avoid being disabled for clicking your own ads. See the Best Practices guide for more details on enabling test ads.
You can download an example project containing this code here and may alternately create your banner in XML.

The Result

When you now run your app you should see a banner at the top of the screen:

Thursday, January 5, 2012

Developing With Flash CS5 for Adobe AIR on Android




Now that Adobe AIR is available for Android 2.2, it is easy to move your Flash games to Android’s app store and also to add functionality that takes advantage of things like the camera and GPS.
AIR stands for Adobe Integrated Runtime and was originally for
...building rich Internet applications using Adobe Flash, Adobe Flex,
Adobe Dreamweaver (HTML or Ajax), AIR SDK, that can be run as 
desktop applications.
But now seems to be headed toward becoming an easy way to quickly develop powerful applications for smartphones, TV’s, car dashboards, tablets, big computers, tiny computers and everything in between.
http://www.adobe.com/products/air/

Setting up your development environment

1. Get Flash CS5 (you can get a 30 day free trial at http://www.adobe.com/downloads)

2. Install Flash extension for AIR http://labs.adobe.com/technologies/flashpro_extensionforair/

3. Install AIR SDK http://www.adobe.com/products/air/

4. Install Android SDK http://developer.android.com/sdk/index.html

Step by step video instructions

Setting up your development environment with Flash CS5 and AIR for Android
http://www.gotoandlearn.com/play.php?id=123

More instructions for setting up.

Getting started with Adobe AIR for Android
http://www.adobe.com/newsletters/edge/august2010/articles/article1/index.html

Some AIR for Android examples

Build a GPS Speedometer
http://mobile.tutsplus.com/tutorials/android/build-a-gps-speedometer-getting-into-air-for-android/

AIR for Android MazeFM Application
http://www.flashandmath.com/mobile/mazefm/index.html

Air for Android: Geolocation
http://www.unitedmindset.com/jonbcampos/2010/08/30/air-for-android-geolocation/

Simple camera application with Flash CS5 and AIR for Android
http://www.gotoandlearn.com/play.php?id=124

Publishing AIR for Android Applications to the App Store
http://www.gotoandlearn.com/play.php?id=131

The .apk file that is created for AIR for Android has the .swf file in the assets folder and an application.xml file in the assets/META-INF/AIR folder which works with the main AndroidManifest.xml file to set the programs application properties and how it should start (run the swf file).

Now it’s easy to move your Flash apps and games to the mobile market. Enjoy.

Wednesday, January 4, 2012

Installing Adobe AIR for Android


Before you can start developing you’ll need to download and install the following components:
  1. Flash Professional CS5 (30-day trial version will do)
  2. The Adobe AIR runtime for Android 2.2
  3. The Adobe Flash Professional CS5 Extension for AIR 2.5
  4. USB Device Drivers (Windows Only)
  5. Adobe AIR 2.5.1 SDK
If you don’t already have Flash CS5 then you can download a 30-day trial from Adobe.
If you plan to deploy and test on an actual handset then you’ll need to install the free Adobe AIR runtime from the Android Market (just search for Adobe AIR in the Market application).
I used a Google Nexus One for this tutorial but AIR will run on Android devices that meet the following system requirements:
  • Android 2.2 operating system
  • ARMv7-A processor with vector FPU
  • OpenGL ES 2
  • H.264 and AAC hardware decoders
  • 256MB of RAM
If AIR for Android is not supported for your Android handset then you can still follow this tutorial and test in Flash CS5.
You can download the Extension for AIR 2.5 from Adobe Labs. Instructions detailing how to install the Extension can be found here. If you’re using Windows then you’ll also need to follow the steps detailing how to install USB device drivers that allow your Android device to communicate with the Android SDK.
Finally, download and install the latest version of the Adobe AIR SDK.
Okay, we’re read to start coding.

Creating your first AIR application for Android with the Flex SDK


To begin, you must have installed and set up the AIR and Flex SDKs. This tutorial uses the AMXMLC compiler from the Flex SDK and the AIR Debug Launcher (ADL), and the AIR Developer Tool (ADT) from the AIR SDK. SeeSetting up the Flex SDK.
You must also download and install the Android SDK from the Android website, as described in: Android Developers: Installing the SDK.
Note: For information on iPhone development, see Creating a Hello World iPhone application with Flash Professional CS5.

Create the AIR application descriptor file

This section describes how to create the application descriptor, which is an XML file with the following structure:
<application xmlns="..."> 
    <id>...</id> 
    <versionNumber>...</versionNumber> 
    <filename>…</filename> 
    <initialWindow> 
        <content>…</content> 
    </initialWindow> 
    <supportedProfiles>...</supportedProfiles> 
</application>
  1. Create an XML file named HelloWorld-app.xml and save it in the project directory.
  2. Add the <application> element, including the AIR namespace attribute:
    <application xmlns="http://ns.adobe.com/air/application/2.7"> The last segment of the namespace, “2.7,” specifies the version of the runtime required by the application.
  3. Add the <id> element:
    <id>samples.android.HelloWorld</id> The application ID uniquely identifies your application along with the publisher ID (which AIR derives from the certificate used to sign the application package). The recommended form is a dot-delimited, reverse-DNS-style string, such as "com.company.AppName".
  4. Add the <versionNumber> element:
    <versionNumber>0.0.1</versionNumber> Helps users to determine which version of your application they are installing.
  5. Add the <filename> element:
    <filename>HelloWorld</filename> The name used for the application executable, install directory, and similar for references in the operating system.
  6. Add the <initialWindow> element containing the following child elements to specify the properties for your initial application window:
    <content>HelloWorld.swf</content> Identifies the root HTML file for AIR to load.
  7. Add the <supportedProfiles> element.
    <supportedProfiles>mobileDevice</supportedProfiles> Specifies that the application only runs in the mobile profile.
  8. Save the file. Your complete application descriptor file should look like this:
    <?xml version="1.0" encoding="UTF-8"?> 
    <application xmlns="http://ns.adobe.com/air/application/2.7"> 
        <id>samples.android.HelloWorld</id> 
        <versionNumber>0.0.1</versionNumber> 
        <filename>HelloWorld</filename> 
        <initialWindow> 
            <content>HelloWorld.swf</content> 
        </initialWindow> 
        <supportedProfiles>mobileDevice</supportedProfiles> 
    </application>
This example only sets a few of the possible application properties. There are other settings that you can use in the application descriptor file. For example, you can add <fullScreen>true</fullScreen> to the initialWindow element to build a full-screen application. To enable remote debugging and access-controlled features on Android, you also will have to add Android permissions to the application descriptor. Permissions are not needed for this simple application, so you do not need to add them now.
For more information, see Setting mobile application properties.

Write the application code

Create a file named HelloWorld.as and add the following code using a text editor:
package 
{ 
    import flash.display.Sprite; 
    import flash.text.TextField; 
     
    public class HelloWorld extends Sprite 
    { 
        public function HelloWorld() 
        { 
            var textField:TextField = new TextField(); 
            textField.text = "Hello, World!"; 
            stage.addChild( textField ); 
        } 
    } 
}

Compile the application

Before you can run and debug the application, compile the MXML code into a SWF file using the amxmlc compiler. The amxmlc compiler can be found in the bin directory of the Flex SDK. If desired, you can set the path environment of your computer to include the Flex SDK bin directory. Setting the path makes it easier to run the utilities on the command line.
  1. Open a command shell or a terminal and navigate to the project folder of your AIR application.
  2. Enter the following command:
    amxmlc HelloWorld.as 
Running amxmlc produces HelloWorld.swf, which contains the compiled code of the application.
Note: If the application does not compile, fix syntax or spelling errors. Errors and warnings are displayed in the console window used to run the amxmlc compiler.

Test the application

To run and test the application from the command line, use the AIR Debug Launcher (ADL) to launch the application using its application descriptor file. (ADL can be found in the bin directory of the AIR and Flex SDKs.)
 From the command prompt, enter the following command:
adl HelloWorld-app.xml 
For more information, see Device simulation using ADL.

Create the APK package file

When your application runs successfully, you can use the ADT utility to package the application into an APK package file. An APK package file is the native Android application file format, which you can distribute to your users.
All Android applications must be signed. Unlike AIR files, it customary to sign Android apps with a self-signed certificate. The Android operating system does not attempt to establish the identity of the application developer. You can use a certificate generated by ADT to sign Android packages. Certificates used for apps submitted to the Android market must have a validity period of at least 25 years.

Generate a self-signed certificate and key pair

 From the command prompt, enter the following command (the ADT executable can be found in the bin directory of the Flex SDK):
adt -certificate -validityPeriod 25 -cn SelfSigned 1024-RSA sampleCert.pfx samplePassword
This example uses the minimum number of attributes that can be set for a certificate. The key type must be either 1024-RSA or 2048-RSA (see the ADT certificate command).

Create the AIR package

 From the command prompt, enter the following command (on a single line):
adt -package -target apk -storetype pkcs12 -keystore sampleCert.p12 HelloWorld.apk HelloWorld-app.xml HelloWorld.swf
You will be prompted for the keystore file password. Type the password and press Enter.
For more information, see Packaging a mobile AIR application.

Install the AIR runtime

You can install the latest version of the AIR runtime on your device from the Android Market. You can also install the runtime included in your SDK on either a device or an Android emulator.
 From the command prompt, enter the following command (on a single line):
adt -installRuntime -platform android -platformsdk
Set the -platformsdk flag to your Android SDK directory (specify the parent of the tools folder).
ADT installs the Runtime.apk included in the SDK.

Install the AIR app

 From the command prompt, enter the following command (on a single line):
adt -installApp -platform android -platformsdk path-to-android-sdk -package path-to-app
Set the -platformsdk flag to your Android SDK directory (specify the parent of the tools folder).
You can launch your app by tapping the application icon on the screen of the device or emulator.