Showing posts with label Create Air App for Android. Show all posts
Showing posts with label Create Air App for Android. Show all posts

Wednesday, January 19, 2011

Develop Android App using PhoneGap on Eclips

Developing cross platform application is on pick in today's world. PhoneGap plays major role in providing cross device development using html and javascript. Using PhoneGap you can develop applications for Android, iPhone, Blackberry and many more mobile OS. Good part is it packages the application in the native formate of the OS.

Today I will walk you through the tutorial which will demonstrate the steps to develop the Android Hello World application.


To Run this tutorial you need Android SDK and Android Emulator. Make sure you have created at least one Android virtual device (AVD). You will also need PhoneGap API. Download the latest copy of PhoneGap. For this tutorial we are only look in the Android development.

Now we have all the required material available to develop First application for Android using PhoneGap First you need to set the Android SDK in Eclips, To do so click on Preferences > Android. Set the Android sdk as shown below.



Next we will create the new project. Click on File > New > Android Project



Now give all required details as shown in the below image to create the project and click finish.



We will require following two files, which was downloaded earlier
1. Android/phonegap-0.9.3.jar
2. Android/phonegap-0.9.3.js

Create libs folder in the project and Place phonegap-0.9.3.jar in it. Also create the www folder within the assets folder and place the phonegap-0.9.3.js in it. (Refer below image)



Next we have to add phonegap-0.9.3.jar in library to access it in the application.
Righ Click on project > properties > java Build Path. In the window click on Add Jars… button to add the phonegap-0.9.3.jar file. Navigate to the location of the jar file and click Ok. This will add your jar file in the library.



Now, create index.html in your www folder and add following code

<!DOCTYPE HTML>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>Hello World</h2>
<script type="text/javascript" charset="utf-8" src="phonegap-0.9.3.js"></script>
</body>
</html>

As we are using phoneGap, we will require some modification in main App.java file. Open the file and do following changes..
1. Change the class's extend from Activity to DroidGap
2. Replace the setContentView() line with super.loadUrl("file:///android_asset/www/index.html");
3. Add import com.phonegap.*;
Now your class should look like as follow.



package com.shailesh;

import android.app.Activity;
import android.os.Bundle;
import com.phonegap.*;


public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}


Finally, lets add some permissions to the AndroidManifest.xml file to allow phonegap to run properly.
Open up your manifest and paste the following information after the versionName but before the application tag:




















Now your xml should look like this.



Now you can run you project as an Android Application. Right click the project and go to Run As and click Android Application. Eclipse might ask you to select an appropriate AVD. If there isn't one, then you'll need to create it before you can continue.

There you go, you have done your first phoneGap application. It will load on the emulator.




Read more...

Sunday, December 5, 2010

Calling and SMS through AIR application on Android Device

Adobe AIR 2.5 has support for two additional URI. Earlier we had mailto URI to navigate to system default email client. Similarly if you want to use system (Mobile) calling client you can do that using tel: URI or if you want to use system(Mobile) SMS client you can do that using sms: URI.

In this article, I will walk you through how we can access the mobile default calling / SMS client. To understand this article one should have knowledge of AS3 and deploying AIR application on mobile. If you are new to this technology (Air on Android). You can refer to my previous post to understand the deployment procedures.

Adobe has launched preview released of Flash Builder Burrito with Hero Flex SDK. We will use Hero Flex SDK to create this simple application.



See code snipped for the application below.



xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
title="Dial or SMS">

horizontalAlign="center"
paddingTop="10" paddingLeft="10" paddingBottom="10" paddingRight="10"/>




protected function callBtn_clickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("tel:"+telNumber.text));
}

protected function smsBtn_clickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("sms:"+telNumber.text));

}

]]>






width="100%"
restrict="0-9"/>
width="100%"
gap="5"
paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5"
verticalAlign="middle" horizontalAlign="right">
label="Call"
click="callBtn_clickHandler(event)"/>
label="SMS"
click="smsBtn_clickHandler(event)"/>




If you notice in the script tag, There is a navigateToURL method executed on Clicking of Call / SMS button.

Following code will trigger the default system calling client.

navigateToURL(new URLRequest("tel:"+telNumber.text));
This method will open up the dial panel of the mobile phone. See below image.

Following code will trigger the default system calling client.

navigateToURL(new URLRequest("sms:"+telNumber.text));
This method will open up the SMS panel of the mobile phone. See below image.


Note: Body and subject attributes is not supported in sms: URI like we do for the mailto: URI due to the limited support from the android API.

I hope this will help you.


Read more...

Thursday, November 25, 2010

Meter Down Application for Android: Developed using Flex Hero

Finally I got a chance to explore Adobe Flash Builder Burrito (Flex Hero SDK). It has support for developing Cross-platform Air application. Currently it is supporting Android only. Hope we will see all other Mobile, Tablets also covered in final version of Hero SDK.

To do experiment, I had decided to develop an application. I want to develop an application which can be useful to the user. After thinking for enough hours, I have decided to develop an application which will help user to get the Mumbai Auto and Taxi Fare for the meter reading. I heard from my relatives, freinds that they had been cheated by Auto and Taxi driver for fares.

Here it is Meter Down application for Android Mobile OS. In this current version, I have covered only Mumbai city. May be I will add more cities in future. I will really appreciate if you can share the meter card for Auto or Taxi from your city.

The current application is having feature of getting Regular as well as Night Fare for Auto and Taxi. The night fare will be calculated based on the mobile time. If it is between 12.00 AM to 5.00 AM, it will show night fare.

You can download APK of this application from here.

You can download Air Runtime APK (Runtime_Device_Froyo_20100826.apk) from here.


Note: Change the file extention of downloaded file to .apk before installing on your device.

I hope this will help you while you travel in MUMBAI by Auto / Taxi.






Read more...

Tuesday, August 31, 2010

Create AIR App for Android Mobile

The demand for smart phones has been increased rapidly. IPhone is one of my favorite smart phones. I really love it. Unfortunately I can't afford right now.

While surfing for the smart phones on internet, I come across an open source OS developed by Google named Android. Recent version of Android (FROYO) has support for the AIR apps also. After doing some research and surfing, my preference for the IPhone has shifted to Android based phones. The support for the AIR has made me more curious to try out Android OS. Luckily Google has emulator for this. No need to spend lots of money in beginning.

After doing decent research, I had decided to give a try to develop AIR App for Android. I would like to share my experience through this tutorial, which will take you through the creation of Digital Watch AIR application for Android using Adobe Flash professional CS5 and testing it on the Emulator. For this tutorial I will use the Flash professional CS5

Adobe and Google are working together to make this happen for android OS. Hope we don't have memory issue for the Android based mobiles.

To execute this tutorial you will require following things.

  1. Adobe Flash Professional CS5
  2. AIRforAndroid_FlashCS5_ yyyymmdd.zxp
  3. Android SDK – Android Emulator
  4. Runtime_Emulator_Froyo_yyyymmdd.apk

To get the AIRforAndroid_FlashCS5_20100826.zxp, you need to register for the Adobe Prerelease site. After registration, download the AIRforAndroid_FlashCS5_20100826.zxp. To install this .zxp you will require Adobe Extension Manager.

After installing the Air for Android extension, when you open the Flash CS5 you will get the option for creating Flash file for android.


After opening the fla file, Save the fla file with DigitalWatch.fla name.
I have created simple Digital Watch Application using Date and Timer class. For this application, I didn't create any classes. I have coded within the FLA. I know it is not good, But just for this tutorial, I have used my earlier code.

Download FLA from here.

Once you are set with the fla running successfully, without any error. You are ready to deploy that for the Android. Before doing this you need to make some configuration within the AIR Android Settings. To do so, Open File > Air Android Settings… This will open up a window to configure the Application for the Android.

As shown in the above image, the default details for the Application appear as per the fla name. DigitalWatch.apk is the actual package file for the Android. This will be installed in the Android Device / Emulator. I have just made few changes, first for the App name: to Digital Watch and checked the Auto Orientation check boxes. If you notice, within the Include Files there are two files added DigitalWatch.swf and DigitalWatch-app.xml. These are the default files which require packaging the AIR app for android. You can add other files whichever are required for executing your application simply by clicking on the button above that.

In the second Deployment tab you will find some more form items, Similar to AIR package, we have to provide the certificate for the Android package also. If you have any certification already created, Navigate to that file and provide the password. I will create a new certification just to explain. Click on the create button to create a new Certification file for the Air package. This will open another window, just fill all required details and save the file at your desired location. See below image for the details.

After creating the certificate file, you need to add the password for that file in password field of the Development Tab. You need to do some more settings within this tab, Just click on the Release Radio button to create the release build. Also uncheck the two check boxes within the After Publishing area, this can be used when we have actual device connected with USB.

In the Third Icons tab, you have to provide icons of different sizes. Here for this tutorial I am not adding any icon, If you don't add any icons then it will take default android icons for your Air application.

Click on publish button to publish the apk file for your AIR Application, Which will be installed on your Android Device or Emulator. We have completed first step of creating AIR app for Android, Now we need to deploy on the Android Device or Emulator. I am using Emulator for this tutorial, since I am not having any Android Device with 2.2 OS.

Next step is to download the Android SDK and configure your emulator for the testing of your Air app. You can download that from the Adobe prerelease page. Download the android-sdk_r06-windows.zip and Runtime_Emulator_Froyo_20100802.apk for setting emulator. Unzip the android sdk to your system at your desired location. I always prefer to unzip that on c:\sdks\android\ location. Next you have to set the path environment variable for the android sdks like we do for the java. Following are the steps to set the path environment variable on windows.

  1. Right-clicking on the My Computer icon and choose Properties from the menu.
  2. Under the Advanced tab, click the Environment Variables button.
  3. Select the Path entry in the System variables section of the Environment Variables dialog and click Edit.
  4. add the following text at the end of the current value:
    ';C:\SDKs\AIR\bin;C:\SDKs\Android\tools'
  5. Click OK.

Now you have set the environment variable for the Android SDK. You are all set to deploy your application on the android emulator. Next step is to open the emulator and creating the AVD (Android Virtual Device).
Now navigate to the tools folder in the android SDK folder, for my case C:\sdks\android\tools. Once you are on this folder click on the android.bat file to start the AVD manager (Refer Below Image). Once the AVD manager open, you need to install all require packages. To install this, click on the Install Package and click on update all, this will update all required packages for the emulator. For Air application, we will require only 2.2 Froyo platforms.


After updating all packages, Next step is to create the AVD for your emulator. To do so, navigate to the virtual device tab and click on the new button. This will open up a window to set up the virtual device (Refer Below Image). Fill all required details as mentioned in the below image. Make sure you choose the Target as Android 2.2 – API Level 8. You can also set the hardware's as per your requirement, for this tutorial we don't required any specific hardware's, Hence we are keeping it as default. After filling all details click on CreateAVD button to create the new virtual device.


Now you are ready to upload your Air App on your virtual device and test. Select the myAVD from the list and click on the Start button to start the virtual device. This will open up a Launch Option window, Simple click launch to open the virtual device. This will open up the virtual device.


Now you are all set to install your Air application. To install your application on emulator, you need to use command line functions of the android sdk. Open a command window and check whether your android sdk is set properly or not. To test this just type android on your command window, this will open up the AVD manager. If it is set properly, it will open the AVD manager if not, Set the android path environment variable as mention above. Once it is set and running properly, Check whether the device you have created are available to sdk or not, to test this type 'adb devices' this will give you list of devices running.

Now your devices are ready and running, next you have to install Air runtime in the emulator. To install this simply navigate to your folder in command window, where you have store your Air runtime apk file (Runtime_Emulator_.apk) As we are running our App on emulator we have to install Emulator apk. Execute adb -e install -r Runtime_Emulator_Froyo_yyyymmdd.apk command. This will give you success message. That means the Air runtime is installed successfully on your virtual device.

Remember in the above command –e stands for the emulator, when you are installing apk on emulator you have to use –e and when you are installing your apk on actual device you have to ue –d. Also the apk for the device is different than the emulator apk. To install in the apk on your device use Runtime_Device_Froyo_20100802.apk file. The command for installing apk on your device is adb -d install -r Runtime_Device_Froyo_yyyymmdd.apk

Next you can install your application using command line function. Simply navigate to your folder in command window, where you have store your apk file for AIR application. Execute following command adb -e install -r DigitalWatch.apk this will give you a success status as shown in below image. You have installed your Air app in the emulator.


Go to AVD window and check in the menu screen, you will find the digitalwatch icon (Refer below image).

Simple click on the icon, it will run your Digital Watch Air app on the emulator. It runs little slow on the emulator, but I am hoping that on actual device it will run faster.

I hope, this tutorial will help you to try out Air on Android. Your suggestion and queries are welcome; Keep commenting to encourage me to write more blogs.

Download the source and apk from here.



Read more...