Pages

Friday, February 21, 2014

Android Application programming made simple

                                               
                                                  Android Application Development


Hi all. I welcome you all to my blog. 

Let us start to code our first Android application.

To start with., 

Open Eclipse -> Project -> Android Application Project

eclipse-new-android-project



eclipse-android-application-project

In the screen that appears choose an Application Name, Project Name and Package Name. Choose a Target API and minimum SDK.

eclipse-android-application-hello-world

  • The application name is shown in the Play Store, as well as in the Manage Application list in the Settings.

  • The Project name is only used by Eclipse, but must be unique within the workspace. This can be typically the name of the application.

  • The Package name must be a unique identifier of your project. It is typically not shown to the users, but it “must” stay the same for the lifetime of the application; it is how multiple versions of the same application are considered the “same app”.

  • Choose a Target API to Compile the Android code
  • For minimum required SDK, select the lowest version of Android that your application will support. Lower API level targets more devices. 
Click Next to move to next screen

Screen 2: In this screen you can configure launcher icon, by selecting the requiredimage based on DPI

eclipse-android-configure-launcher-icon

Click Next to move to next screen

Screen 3: This screen is used to create a layout activity for ur designs.

eclipse-android-create-activity

Select the black activity and click on Next.


Screen4:

In this screen give the Activity name and layout name you wish to have(Make it relevant to the activity for understanding what class is used for what) and click Finish to complete the setup.
eclipse-android-blank-activity

Once you click on Finish the IDE opens with DIRECTORY structure as shown below for your reference:

Android Directory Structure

As you can see the directory structure has many folders and files.

src folder : This folder contains java class files that we use in the project.

res folder : This folder contains all drawables(hdpi,ldpi,mdpi,xdpi classified based on pixel density of images), Layouts (Contains all out xml files that is used for our User Interface Designs) that we will be using in our project. 

AndroidManifest.xml file : This is file that is like a heart of an Android Application. We declare all activities created in out project.
  • Manifest file for an android application is a resource file which contains all the details needed by the android system about the application.
  • It is a key file that works as a bridge between the android developer and the android platform.
  • It helps the developer to pass on functionality and requirements of our application to Android. 
  • This is an xml file which must be named as AndroidManifest.xml and placed at application root. 
  • Every Android app must have AndroidManifest.xml file.   

Android Manifest files will contain the following elements:

<action>
<activity>
<activity-alias>
<application>
<category>
<data>
<grant-uri-permission>
<instrumentation>
<intent-filter>
<manifest>
<meta-data>
<permission>
<permission-group>
<permission-tree>
<provider>
<receiver>
<service>
<supports-screens>
<uses-configuration>
<uses-feature>
<uses-library>
<uses-permission>
<uses-sdk>

A sample Android Manifest file for your reference:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.javapapers.android"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".HelloWorld" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Create layout design for our application.


  • Open activity_main.xml(default)
  • You have 2 views in this xml editor screen., such as., Graphical layout or xml code layout. Use can switch between the layout views to see your design and code
  • Use the tools needed for ur design that is available in Palette pane in Graphical layout.




Once design is done now its time to code our activity. So open MainActivity.java from src folder in project hierarchy.




The above image shows the sample of how our MainActivity.java looks like. You can write your java code here.

Example Program:


Display you a welcome message on clicking a button.


Activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/welcomebtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Click me" />

</RelativeLayout>

MainActivity.java:

package com.example.welcome;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

Button hi;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

hi = (Button) findViewById(R.id.welcomebtn);

hi.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "Hi!!! ... Welocme you all for your first Andorid Application",
  Toast.LENGTH_LONG).show();
}
});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


Manifest File:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.welcome"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.welcome.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Compiling the Android Application:

After u have done the code:

 Click on Run–>Run as  Android Application.

As i mentioned Before u run, if u have created AVD ., else go back to my earlier post and know how to make AVD's. 

 Enjoy your first app on ur emulator and install the .apk file from bin folder in your Project Hierarchy.


Happy Coding...

Be Good Do Good... 


 






Thursday, February 20, 2014

IDE for Android Development

Hi all,

    I welcome u all for my next post. As i promised i am here to tell u all what is a IDE and getting started with making a IDE for developing Android Application.

Everyone say IDE. But what Actually an IDE is???

Its simple my friends. 

  • IDE stands for Integrated Development Environment. 
  • I think i am using some complex words here to abbreviate IDE.
  •  In simple words, IDE is a place where we Work/Code also known as "Editor".
  •  It is a programming environment meshed into a software program. It provides a text or code editor, a GUI builder, a compiler, interpreter and debugger.
  •  Programs such as Visual Studio, Delphi and Dream Weaver are all examples of IDE's.
Android also uses a Editor or IDE for developing Android Applications.

  • Android IDE is a full blown integrated development environment (IDE) for developing directly on Android devices. 
  • AndroidIDE currently supports developing native Android apps using Java and/or C/C++, as well as developing cross-platform PhoneGap apps using HTML5/CSS/JavaScript. 
  • AndroidIDE supports the full edit-compile-run cycle: Write code with a feature-rich editor offering advanced features like code completion, real-time error checking, refactoring, smart code navigation, and run your App with a single click. 
  • AndroidIDE will turn your Android tablet with a keyboard into a real development box. 
  • AndroidIDE will turn your Android Phone into a small development computer to browse and touch up your code on the go.
Eclipse IDE for Android Development:
               
Let me start telling you how u get these screens on ur system:

Basic System Configurations:

To start with:
You can start your Android application development on either of the following operating systems:
  • Microsoft Windows XP or later version.
  • Mac OS X 10.5.8 or later version with Intel chip.
  • Linux including GNU C Library 2.7 or later.                                                                          
Next,  
 Following is the list of software's you will need before you start your Android application programming. All these are freely available on Internet for free download. 
Once downloading SDK, ADT bundle and Eclipse from above link, u r all set to create IDE for creating your first Android Application. 

Few steps before that to be made.

Set up Environment Variables to use Jar libraries and ADT in android application developement:
  • Goto System properties (Start -> My Computer -> Properties -> select Advanced option) and select Environment Variables.
  • Select PATH from Edit panel and set the JAVA Home Path to ur JAVA Bin path. (Eg: JAVA_HOME=C:\jdk1.6.0_15)

Setting up SDK Manager:

  • Open Eclipse.
  • In Eclipse, select the menu Window->Android SDK Manager
  • If the Android SDK location was not set up correctly within Eclipse, go to Windows-> Preferences->Android,  and set the SDK location field to the root of your SDK install directory.(SDK path is the Path where you have put ur unzipped Android SDK folder). Select that path and set SD path
  • In the Android SDK manager window, sort by API level, click 



  • Now Goto Windows -> Android SDK Manager . Following window opens up.
  •  This window displays list of Android SDK available  beginning from oldest version to latest version on the top. Select the version you want to develop your android applications. 
What is IDE and How to Create AVD???


  • Before launching the emulator, you must create an Android Virtual Device (AVD) which defines the system image and device settings used by the emulator. Some of the settings are,
  • configure the version of the Android system
  • size of the SD card
  • set of hardware options
  • emulator skin
  • screen resolution, etc
  • You can define several AVD with different configurations and can start them in parallel.
  • Starting a new emulator is very slow, because the file system of the new AVD needs to get prepared.
How to create AVD??

  • In Eclipse, select Window -> AVD Manager.
  • Click New…
The Create New AVD dialog appears.
  • Type the name of the AVD, for example “first_avd“.
  • Choose a target.
    • The target is the platform (that is, the version of the Android SDK, such as 2.3.3) you want to run on the emulator. It can be either Android API or Google API.
  • [Optional] an SD card size, say 400
  • [Optional] Snapshot. Enable this to make start up of emulator faster.
    • To test this, enable this option. Get the emulator up and running and put it into the state you want. For example, home screen or menu screen. Now close the emulator. Run it again and now the emulator launches quickly with the saved state.
  • [Optional] Skin.
  • [Optional]You can add specific hardware features of the emulated device by clicking the New…button and selecting the feature. Refer this link for more details on hardware options.
  • Click Create AVD.

How to Launch AVD??
After creating a new Android AVD, you can launch it using “Android AVD Manager”.
Open “Android AVD Manager” either from Installation directory or Eclipse IDE and follow the steps as shown below.
 


Now we all are set to start coding our first project in Android.

Please refer below video tutorials for your reference.  

IDE for Android Eclipse Setup Reference Video

http://www.youtube.com/watch?v=BLLX9EtG6CI

In my next post i shall teach how to create our first Android project.

All the Best.. Good luck..


                                                                Be Good Do Good...

Android Application Development made easy


                                

Hello all,

           Here I am back to all with a new domain. I am writing this blog to share with u all about the currently rocking domain (Mobile Technology).

First let me tell u what is Mobile technology???
I am very sure everyone in all corners across globe use mobile and very familiar in using many mobile applications.
What is Mobile Technology??

Mobile technology is the technology used for cellular communication. Mobile Code Division Multiple Access (CDMA) technology has evolved rapidly over the past few years. 

Since the start of this millennium, a standard mobile device has gone from being no more than a simple two-way
Mobile applications or mobile apps are applications developed for small handheld devices, such as mobile phones, smartphones, PDAs and so on. Mobile apps can come preloaded on the handheld device as well as can be downloaded by users from app stores or the Internet.
You can find mobile apps on both feature phones and smartphones. The most popular smartphone platforms that support mobile apps are IOS, Android, Windows Mobile, Symbian, Java ME and Palm.

Here I am going to talk to u all about the Android application Development from basics. I will be discussing with u all about basic requirements to build a basic android application.

Learn Android Programming 

What is Android and Android Development???
Android is an open source and Linux-based operating system for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies.
This class teaches you how to build your first Android app. You’ll learn how to create an Android project and run a debuggable version of the app. You'll also learn some fundamentals of Android app design, including how to build a simple user interface and handle user input.
This tutorial has been prepared for the beginners to help them understand basic Android programming. After completing this tutorial you will find yourself at a moderate level of expertise in Android programming from where you can take yourself to next levels.
Android programming is based on Java programming language so if you have basic understanding on Java programming then it will be a fun to learn Android application development.
See my next post get ready to take off with Setting up IDE for creating Android Applications. 

Have a lovely day ahead.. Good luck...  


                                                             Be Good Do Good