Showing posts with label Android Beginners. Show all posts
Showing posts with label Android Beginners. Show all posts

Wednesday, 6 February 2013

[Tutorial] Some Easy Steps For Google Map View Example For Android


Steps 1: OBTAIN GOOGLE API KEY


To make use of Google Map or any other Google API you need to have a Google API key.
It is extremely easy to get a Google API Key. You see below I have made a Video which is made up of            step-by-step procedure for obtaining the Google API key.


DETAILED STEPS FOR GETTING GOOGLE API 



  1. Proceed to the location exactly where JDK installed.
  2. Certainly, there you will see KeyTool.
  3. Then simply Copy the path.
  4. Start a command prompt then change the directory to the keytool path.
  5. copy and paste the below code snippet to command prompt



keytool -list -alias androiddebugkey -keystore





  1. At this point we need to copy the path of the debug.keystore
  2. Head over to windows/users/[your computer user name]/.android/
  3. It’s simple to find the debug.keystore, so copy the path.
  4. Next paste the keystore path surrounded with “” combined with the step 5 code snippet.




keytool -list -alias androiddebugkey -keystore "C:.android.keystore" -storepass android -keypass android



  • Last but not least press Enter. You will notice the Certificate Finger Print.

https://developers.google.com/android/maps-api-signup



  1. Enter the Finger print using only number and digits. Stay away from including “:” .
  2. After that Tick the Agreement.
  3. Simply click Generate API key. You should see the API key now. Copy the actual URL intended for future reference.





Step 2 : Hands-on Google Map in Emulator

Before start to code our Google Map Alert App, we are now going to test it, to ensure we are ready to go.


  1. Start a Sample Project named GoogleMapDemo.





  1. Choose the Choose bulid SDK to Google API. I choosed Google API Level 16.
  2. Then Click Next for the rest, Finally press Finish.


  • Copy the below code to your Layout.

res/layout/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" >

    <com.google.android.maps.MapView
android:id="@+id/map"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:clickable="true"
  android:apiKey="06Q7KxHWP0w3-i0IpzRr8sSRnDLyHWAfJ_lk8mQ" />

</RelativeLayout>

NOTE:Here you should enter your apikey otherwise it won’t work.


Ok in case you are so curious, then simply run it. You will find the below stopped message.



Android Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapdemo"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <uses-library android:name="com.google.android.maps"/>
        
    </application>
    
    <uses-permission android:name="android.permission.INTERNET"/>

</manifest>


Do you believe that this time, it’s going to run the app and show the map.
I am not going to say anything at the moment, just proceed as well as run the project




So above is the answer. So for we have extends only Activity, but in order to make use of Google Map, Our Java Code should extends MapActivity. :)

src/com.example.androidmapviewdemo/AndroidMapViewDemo.java

package com.example.googlemapdemo;

import com.google.android.maps.MapActivity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;

public class MainActivity extends MapActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}

    
}






So now the map is shown but we can only pan/move the map. No other functionality like zooming, map the entered address, get address by simply touching on the map, drawing overlay to display some images to point out the selected locations and many interesting things we are going to do in our next tutorial.




YOU MAY ALSO LIKE::




Read More

Thursday, 31 January 2013

[How To]Easy steps for Install Android 4.1.2 Jelly Bean On Samsung Galaxy S2 GT-I9100G Using Custom ROM Avatar [Tutorial]



If you are a Samsung Galaxy S2 owner and want to experience the new Android 4.1.2 Jelly Bean on your device, you probably won’t have to wait for long as the company will reportedly roll out the firmware update for the Galaxy S2 in the beginning of February in Singapore with other countries expected to follow thereafter.

For those who are in a hurry, thanks to custom ROM Avatar, you can try your hands on Android 4.1.2 Jelly Bean on your Galaxy S2 with the model number GT-I9100G even before that. According to a report from Android Jinn, one of the main features of Avatar ROM is that it combines customization of CM10 with the theme engine of MIUI.

“By installing Avatar ROM you will get all customization of CM10 Android 4.1.2 Jelly Bean custom ROM as well and also install eye candy themes of MIUI ROM,” said the report.

Given below is a tutorial explaining how to install Android 4.1.2 Jelly Bean on Samsung Galaxy S2 GT-I9100G using custom ROM Avatar. Users should note that the ROM is still under development and therefore users may encounter some issues and bugs. However, all the issues are expected to be resolved as development progresses.

Crucial Points To Remember
- Backup your data and apps.
- The device has at least 80 percent battery power.
- The USB driver must be installed for Samsung Galaxy S2 GT-I9100G in your PC.
- The USB Debugging must be enabled.
- Backup your EFS Folder.
- The device must have ClockworkMod Recovery Installed.
- Flashing this ROM on your device will increase your binary counter.
- Don’t skip Nandroid backup as it’s very helpful if this custom ROM doesn’t work the way you wanted.

Installation Procedure

Step 1: Download Avatar ROM 4.1.2 Jelly Bean ROM For Galaxy S2 I9100G (Filename: AvatarRom.I9100G#ExperimentalBuild2.zip).

Step 2: Download Google Apps (Filename: gapps-jb-20121011-signed.zip).

Step 3: Connect your Galaxy S2 to a PC using USB cable.

Step 4: Copy downloaded files to the SD card of your phone without extracting them.

Step 5: Disconnect the USB and power off your phone.

Step 6: Boot into ClockworkMod recovery in your Galaxy S2 by pressing and holding the Volume Up, Power and Home buttons together. Wait till the Samsung logo appears on screen.

Step 7: Release the buttons and hold them again. You will get ClockworkMod recovery screen soon. Now browse between options in recovery using Volume keys while using Power key to select an option.

Step 8: Perform a Nandroid backup of your existing ROM by selecting Backup and Restore, then on the next screen, selecting Backup again. Once back up is complete, go back to the main recovery menu.

Step 9: Perform the data wiping task. To do so, select the wipe data/ factory reset, then select Yes on next screen to confirm your action. Wait for a few minutes till the data wipe is completed.

Step 10: Select install zip from the sdcard and after that select choose zip from the sdcard. Now, locate the AvatarRom.I9100G#ExperimentalBuild2.zip file and select it by pressing Power button.
Confirm installation by selecting Yes – Install _____.zip on the next screen. The ROM installation will begin.

Step 11: Once the ROM installation is done, repeat the step 10 but choose the gapps-jb-20121011-signed.zip file instead of ROM zip to install the Google apps package.

Step 12: After the installation is completed, go back to the main recovery menu and select reboot system now to reboot the phone and boot up into customized Android 4.1.2 Jelly Bean. The first boot will take time.



Read More

Wednesday, 30 January 2013

[How to]Latest flash ClockworkMod Recovery 6.0.2.5 for the Galaxy S3 [updated] 2013




One of the most attraction point of Android ecosystem is the ability to customize the look and feel as well as capability that user feel better for him/her. And, that’s why there are so many ROMs, hacks, MODs and tweaks are there to extend or customize your Android experience. To achieve all this ability one tool looks always tall is ClockworkMod recovery. CWM recovery is a custom recovery that not only allow you to install ROMs, MODs and other hack but also comes with several system oriented function that stock recovery don’t have. ClockworkMod Recovery 6.0.2.5 is the newest update and it is finally ready for both Galaxy S3 I9300 and I9305, courtesy of XDA Developers member sharingan92.


In this article we will guide you to install ClockworkMod Recovery 6.0.2.5 (touch or non-touch) in Galaxy S3, model number I9300 or I9305. For this, we will use a tool called ODIN that will help us to flash the ClockworkMod Recovery 6.0.2.5 in Galaxy S3. However, in this process you may lose all your existing installed apps and personal settings. You should follow this guide carefully to properly backup your data that you can restore later.

Warning!
This tutorial is only for Galaxy S3, model number I9300 and I9305. Don’t try this guide in any other Android device. Check your device’s model number in: Settings » About phone. Also, we are not responsible for any damage caused due to the instruction given in this page. Try this at your own risk. Although, it is very unlikely that your device will be damaged if you follow all the instructions as it is which are mentioned in procedure.

Pre Requisites:

Backup your data first using below mentioned instructions, so that if you lost any data you can recover it easily.


SMS & Call Log – 

Use SMS, MMS & Call Log Entries Backup & Restore App

Contacts & Settings – 

Use Android default backup options.

Images, Songs, Videos, Files – Copy to Internal/External SD card.

APN and MMS Settings – Note down from the path “Applications > Settings > Wireless and Network > Mobile Networks > Access Point Names”

Important!
  1. Make sure your device have at least 80% battery power. 
  1. You already have USB Driver Installed for Galaxy S3 in your PC. [Download USB Driver]
  1. Make sure USB Debugging is enabled. [Guide]
If you follow everything that we mentioned above, you are ready to move into next page of this guide where we summed up detail instruction on how to flash ClockworkMod Recovery 6.0.2.5 (touch or non-touch) for Galaxy S3 I9300 or I9305.
Read More

How To Backup EFS Folder in Samsung Android Devices


Every Samsung Android devices comes with the infamous EFS folder. So, what EFS folder have and why backup is very important here?

EFS folder is the very sensitive system folder that contains Phone-specific information such as the IMEI (encrypted in the nv_data.bin), wireless devices MAC addresses, product code (also in the nv_data.bin), and much more. If this thing not handled properly, can turn your device completely useless as it will no longer be recognized by your carrier.
Problem is, flashing custom ROMs sometime can corrupt contains within EFS folder. That’s why backing up EFS folder is very important if you love to flash new ROM. Good thing is, XDA Recognized Developer lyriquidperfection develop a tool that can backup and restore ‘/efs’ folder of your device easily called EFS Pro. No need to say, this tool require a rooted device. EFS Pro tool rightly called an advanced ‘/efs’ Backup, Restore and Repair tool.

EFS Pro Key Features
  • Supports Backup and Restore of Partition Image (*.img) and Compressed TAR Archive (*.tar) formats.
  • Automatically detects saved EFS Backups on Device and PC for hassle free restoring.
  • Re-Scan option to refresh Backup list for restoring Backups.
  • Automatically Re-Mounts ‘/efs’ folder with Read/Write permissions during restore for users ‘stuck’ with Read Only permissions.
  • Automatic detection and prompting of Mass Storage Mode.
  • Automatic detection and termination of SAMSUNG Kies application on startup.
  • Supports Multiple Backup handling.
  • Option to Format ‘/efs’ partition before restoring an EFS Backup.
  • Displays various Device, ROM and BusyBox related information on startup.
  • Attempt NV Recovery – Restores NV Data from ‘*.bak’ files if they exist to fix corrupt or incorrect IMEI number.
  • Repair NV Data – Repairs NV Data file ownership to fix ‘Unknown Baseband’ and ‘No Network / Signal’.
  • AUTOMATIC ‘/efs’ partition location detection to add support for many more including future devices.
  • Hashing of Partition Image Backups to verify the data written.

To use this tool, just connect your Samsung devices with your Windows computer and make sure your device is NOT in Mass Storage Mode or Backup and Restore functions will fail.
Download EFS Pro v1.9.12

Now, run EFS Pro.exe file and follow the onscreen instruction to backup or restore your device’s ‘/efs’ folder.

Note: This tool require Microsoft .NET Framework 4.0 and can only work on Windows XP, Vista and 7.

As always, don’t forget to visit official development page to donate the developer as well as download the latest tool.
Read More

How to Enable/Disable USB Transfer on Android Mobile


There are basically two ways to transfer files between PC and Android phone – via USB or via WiFi. USB transfer enabled out of the box, you don’t require to do anything. However, there are sometime you really wish to disable USB transfer or need to enable it when someone else disable it for your discomfort. Enabling/Disabling USB transfer is very easy, just follow the below guide.

How to Enable/Disable USB Transfer on Android Mobile

1. Press Menu key in your home screen and then tap on Settings option.


2. A list of available options jump in front of you. Locate and tap on Applications option.


3. A few Applications related options will be shown in your screen. Navigate and tap on Development option.


4. You will see 3 options in front of you – USB debugging, Stay awake and Allow mock locations. Every option comes with a check box. 

Tap on checkbox and it will turn into green (means activated). Make sure USB debugging is turned on when you want USB transfer else tap on it to deactivate the function.


Hope this small guide help you to solve some trick. We will talk on more about USB Data Transfer and Wi-Fi Data Transfer in our next articles.

Read More

Download All Type Of Android USB Drivers For Windows 7/8/vista OS



Developer as well as users of Android device require USB driver installed for their Android device for various purpose including Adb and Fastboot driver setup, accessing mobile storage in PC, transferring media from computer to mobile etc.

Good thing is, Windows OS most likely install manufacturer specific USB driver as soon as you connect the device first time. However, if it unable to do so then we are here to help you out. The list below helps you to download USB drivers either from manufacturer website or directly from a file hosted website. We use Mediafire as a file host as it allow you to download instantly and support resume for free.

From below given links you can either download the USB driver or PC Suite that comes with the driver.

Download Android USB Driver (Android Phone and Tablet) for Windows OS

Samsung: Download Samsung USB Drivers or Download Samsung KIES (comes with driver)

Sony: Download Sony USB Drivers for Android device

HTC: Download HTC USB Drivers (HTC Sync)

LG: Download LG USB Drivers

Motorola: Download Motorola USB Drivers (Motorola Device Manager)

ASUS: Download ASUS USB Drivers or Download ASUS PC Suite (comes with driver)

Huawei: Download HiSuite (drivers included)

ZTE: Download ZTE USB Drivers

Acer: Download Acer USB Drivers

ALCATEL ONE TOUCH: Download Alcatel One Touch Drivers

Dell: Download Dell USB Drivers

Foxconn: Download Foxconn USB Drivers

Fujitso: Download Fujitso USB Drivers

Garmin-Asus: Download Garmin-Asus USB Drivers

Hisense: Download Hisense USB Drivers

Intel: Download Intel USB Drivers

KT Tech: Download KT Tech USB Drivers

Kyocera: Download Kyocera USB Drivers

Lenevo: Download Lenevo USB Drivers

Pantech: Download Pantech USB Drivers

Pegatron: Download Pegatron USB Drivers

Sharp: Download Sharp USB Drivers

SK Telesys: Download SK Telesys USB Drivers

Teleepoch: Download Teleepoch USB Drivers

Yulong Coolpad: Download Yulong Coolpad USB Drivers

Read More

Wednesday, 23 January 2013

Android Tutorial & Lessons 5: [How To] XML made EASY & Introduce Java



What's up my peepz? (who says peepz anymore?) This lesson will get you up and running, and even if you are an absolute beginner, you can do it.

In this lesson you will learn:

-XML, the Easy way, using the Graphical Layout
-Accessing Properties Tab (and other tabs) in Eclipse
-Making a Button
-Introduction to the id reference in Java
-New XML functions
-Introduction/Review of how the Manifest calls the Java activity which calls the XML layout
-Create a new XML layout
-HOMEWORK: create 3 different icons and place them in the appropriate folders ( create one icon 150x150px for the high density folder, one 75x75 for medium, and one 35x35 for the low density folder)

This video is the 5 in a web series that I am creating to help you learn Android programming so you can create apps and eventually how to learn to write games for android phones. I want to explain things in a way that everyone can understand, even if you have no experience with Java, XML, C, OpenGL, or as a matter of fact, any other programming language.
Read More

Android Tutorial & Lessons 4: [How To]More XML and referencing background




What's up my peepz? (who says peepz anymore?) This lesson will get you up and running, and even if you are an absolute beginner, you can do it.

In this lesson you will learn:
-A better understanding of XML
-Adding a Button
-Find coding that even when we don't remember the exact coding
-Basics of the Linear Layout
-New XML functions
-Adding our picture to the background of our app
-Running our program on the emulator

This video is the 4 in a web series that I am creating to help you learn Android programming so you can create apps and eventually how to learn to write games for android phones. I want to explain things in a way that everyone can understand, even if you have no experience with Java, XML, C, OpenGL, or as a matter of fact, any other programming language.
Read More

Android Tutorial & Lessons 3:[How To] Start learning XML to create custom layouts





What's up my peepz? (who says peepz anymore?) This 

lesson will get you up and running, and even an absolute 

beginner can do it.




In this lesson you will learn:

-Fix the error within the project

-clean project

-start the Android emulator 

-Start learning XML to create layouts (learn the TextView 
coding)

-Learn about referencing strings in resources folder

This video is the 3 in a web series that I am creating to help 


you learn Android programming so you can create apps and 

eventually how to learn to write games for android 

applications. I want to explain things in a way that everyone 

can understand, even if you have no experience with Java, 

XML, C, OpenGL, or as a matter of fact, any other 

programming language.

If you do have a lot of experience with programming, these 


first videos will be really slow for you, but my goal is to get 

everyone sprinting, but for now we have learn to crawl.
Read More

Android Tutorial & Lessons 2:[How To]Setting up a Project and Explaining the Basics


What's up my peepz? (who says peepz anymore?) This lesson will get you up and running, and even an absolute beginner can do it. Sorry I still have that nasty cold, so please forgive my sniffing noises, my strange nasally voice, and other distractions.

In this lesson you will learn:
-How to set an Android Project in Eclipse
-Understand the basic layout of the project, such as the folders
-How to add a picture to the project that we will later use as a background

This video is the 4 in a web series that I am creating to help you learn Android programming so you can create apps and eventually how to learn to write games for android phones. I want to explain things in a way that everyone can understand, even if you have no experience with Java, XML, C, OpenGL, or as a matter of fact, any other programming language.

If you do have a lot of experience with programming, these first videos will be really slow for you, but my goal is to get everyone sprinting, but for now we have learn to crawl.

Read More

Thursday, 17 January 2013

[How To]Setup And Creating Your First Application In Android

                       

1.  Introduction

Android is an Operating System for mobile devices developed by Google, which is built upon Linux kernel. Android competes with Apple's iOS (for iPhone/iPad), RIM's Blackberry, Microsoft's Windows Phone (previously called Windows Mobile), Sambian OS, and many other proprietary mobile OSes.
Android Platform
Android is based on Linux with a set of native core C/C++ libraries. Android applications are written in Java. However, they run on Android's own Java Virtual Machine, called Dalvik Virtual Machine (DVM), which is optimized to operate on the mobile devices.
The mother site for Android is www.android.com. For developers, visit http://developer.android.com to download the SDK, Android Training, API Gudies and API documentation.

2.  How to Install Android SDK

NOTE: Installing all the necessary software needed for Android programming takes times - It could take hours?!
Pre-Installation Check List
Before installing Android SDK, you need to install:
  1. Java Development Kit (JDK): Read "How to install JDK".
  2. Eclipse: Read "How to install Eclipse".

Now, you are ready to install the Android SDK.
Step 0: Read the "Android Training"
Start from Android's mother site @ http://www.android.com.
Goto "Developers" @ http://developer.android.com. There are three main menus: Design, Develop, and Distribute. Start with "Develop", you can find the "Android Training", "API Guides", "Reference" and "Tools". For beginners, browse through the "Android Training".
Step 1: Download the Android SDK
Download the Android SDK from http://developer.android.com/sdk/index.html. For novices, choose the installer version by clicking the button "Download the SDK for Windows" (installer_r20-windows.exe). For Lunix and Mac, select "Other Platforms".
For advanced programmers, I recommend that you choose the ZIP version (under the "Other Platforms") (android-sdk_r20-windows.zip). I prefer the ZIP version, as you could install many versions, rename the directory, and remove the installation easily.
Read "Installing the SDK".
Step 2: Install Android SDK
Run the downloaded installer into a directory of your choice, e.g., "d:\bin\android-sdk"; or unizp the downloaded ZIP file. Take note of the installed directory. Hereafter, I shall denote the android installed directory as <ANDROID_SDK_HOME>.
Step 3: Install Android Platforms and Add-ons via "SDK Manager"
The Android SDK comprises 2 parts: the "tools" and the "Platforms & Add-ons". After running the installer (in the pervious step), the basic "tools" are installed, which are executables that support app development. The "Platforms & Add-ons" consist of ALL Android platforms (from Android 1.x to 4.x) and various Google Add-ons (such as Google Map API), which could be selectively installed.
Now, we have to choose our Android "Platforms & Add-ons".
  1. Launch Android's "SDK Manager", which is responsible for managing the software components. If you have run the installer, it should have started the SDK Manager after the installation. Otherwise, launch the SDK manager by running (double-clicking) "SDK Manager.exe" under the Android installed directory.
  2. In "Add Platforms and Packages", select your target Android platforms and add-ons packages. For novices, select "Android SDK Platform-Tools", and at least one Android platform (e.g., Android 4.1 (API 16)) ⇒ "Install".
Step 4: Install Eclipse Android Development Tool (ADT) Plugin
I suppose that you have installed Eclipse.
  1. Launch Eclipse.
  2. Install Eclipse ADT: From Eclipse's "Help" menu ⇒ "Install New Software..." ⇒ In "Work with", enter https://dl-ssl.google.com/android/eclipse/ ⇒ Check ALL boxes ⇒ Next ⇒ Finish ⇒ Restart Eclipse to use ADT plugin.
  3. Configure Eclipse ADT: From Eclipse's "Window" menu ⇒ Preferences ⇒ Android ⇒ In "SDK Location", select the Android SDK installed directory (e.g., "d:\bin\android-sdk").
Step 5: Create a Android Virtual Device (AVD) (or Emulator) via "AVD Manager"
AVDs are emulators that allow you to test your application without the real devices. You can create AVDs for different android platforms (from Android 1.x to Android 4.x) and configurations (e.g., screen size, orientation, SD card and its capacity).
  1. From Eclipse's "Window" menu ⇒ Preferences ⇒ Android ⇒ In "SDK Location", enter your Android SDK installed directory (e.g., "d:\bin\android-sdk").
  2. From "Window" menu ⇒ AVD Manager. (You could also start the AVD manager by running "AVD Manager.exe" under the Android SDK installed directory.)
  3. In "Android Virtual Device Manager" dialog ⇒ "New".
  4. The "Create New Android Virtual Device (AVD)" dialog appears. In "Name", enter "Android41_Phone". Select the "Target" Android platform, "SD Card Size" (e.g., 10MB, do not set a huge SD Card size, which would take hours to create.) Skin (screen resolution, e.g., WVGA800x480 for smart phone - Wiki "Graphics display resolution" for the various resolution) ⇒ "Create AVD".
You can test your AVD by launching the emulator. Start the AVD manager ⇒ Select a AVD ⇒ Click the "Start" button ⇒ Check "Scale display to real size" to get a smaller screen that could fit in your display ⇒ Launch. Wait patiently! The emulator is very slow and take a few MINUTES to launch. You can change the orientation (between portrait and landscape) of the the emulator via "Ctrl-F11".
We typically create different AVDs to emulate different real devices, e.g., Android41_tablet of resolution (1024x768 XGA).
Step 6: Setup PATH
You can skip this step now if you are not familiar with PATH, but it is needed later.
Include the android's tools directory (<ANDROID_SDK_HOME>\tools) and platform-tools directory (<ANDROID_SDK_HOME>\platform-tools) to your PATH environment variable.
For Windows: Start "Control Panel" ⇒ "System" ⇒ (Vista/7) "Advanced system settings" ⇒ Switch to "Advanced" tab ⇒ "Environment variables" ⇒ Choose "System Variables" for all users (or "User Variables" for this login user only) ⇒ Select variable "PATH" ⇒ Choose "Edit" for modifying an existing variable ⇒ In variable "Value", APPEND your <ANDROID_SDK_HOME>\tools directory (e.g., "d:\bin\android-sdk\tools"), followed by a semi-colon ';', IN FRONT of all the existing path entries. DO NOT remove any existing entry; otherwise, some programs may not run.
Add the platform-tools directory to the PATH too.

3.  Write your First Android Program Using Eclipse ADT

Android apps are written in Java, and use XML extensively. I shall assume that you have basic knowledge of Java programming and XML.

3.1  Hello-world

Step 0: Read
Go to "Android Training" @ http://developer.android.com/training/index.html, Read "Get Started", "Build your first app".
Step 1: Create a new Android Project
  1. Launch Eclipse.
  2. From "File" menu ⇒ New ⇒ Project.. ⇒ Android Application Project ⇒ Next.
  3. The "New Android Project" dialog appears:
    1. In "Application Name", enter "Hello Android" (this is the Android appliation name that shows up on the real device).
    2. In "Project Name", enter "HelloAndroid" (this is the Eclipse's project name).
    3. In "Package Name", enter "com.example.helloandroid".
    4. In "Build SDK", select the latest version (e.g., Android 4.1 (API 16)).
    5. In "Minimum Required SDK", select "API 8 Android 2.2 (Froyo)" - almost all of the Android devices meet this minimum requirement ⇒ Next.
  4. The "Configure Launcher Icon" dialog appears, which allows you to set the application's icon to be displayed on the devices ⇒ Next.
  5. The "Create Activitiy" dialog appears. Check "Create Activity" Box ⇒ Select "BlankActivity" ⇒ Next.
  6. The "New Blank Activity" dialog appears.
    1. In "Activity Name", enter "HelloActivity".
    2. In "Layout Name", enter "activity_hello" (default).
    3. In "Title", enter "Hello" (this title will appear as the screen title) ⇒ Finish.
Eclipse ADT creates a default Hello-world Android app.
Step 2: Run the Android App
Run the application by right-click on the project node ⇒ "Run As" ⇒ "Android Application".
Be patient! It takes a few MINUTES to fire up the emulator! Watch the Eclipse's status bar for the launching progress; and the console view (or LogCat view) for messages.
Once the emulator started, unlock the device by holding and sweeping the "lock" to the right (or left). It shall launch your Hello-world app, and displays "Hello, world!" on the screen with a title "Hello".
If your program is not launched automatically, try launching it from the "app menu" manually, after the emulator is started. Look for the icon "Hello".
Trying launching the app from "HOME" ⇒ "..." ⇒ Look for the icon "Hello".
Also try "HOME" ⇒ "..." ⇒ "MENU" ⇒ "Manage Apps" ⇒ Select "HelloAndroid" ⇒ Uninstall.
NOTE: DO NOT CLOSE the emulator, as it really takes a long time to start. You could always re-run or run new applications on the same emulator.
Run the Android App on Real Devices
To run the Andriod app on the real devices:
  1. Connect the real device to your computer. Make sure that you have the "USB Driver" for your device installed on your computer. You can find the "Google USB Driver" @ http://developer.android.com/sdk/win-usb.html, and Google's certified "OEM USB Drivers" @ http://developer.android.com/tools/extras/oem-usb.html. If you device is not certified there, good luck! It took me many hours to find a compatible driver for my cheap Pad.
  2. Enable "USB Debugging" mode on your real device: from "Settings" ⇒ "Applications" ⇒ "Development" ⇒ Check "USB Debugging". This allows Android SDK to transfer data between your computer and your device.
    Also enable "Unknown source" from "Applications". This allows applications from unknown sources to be installed on the device.
  3. You shall see the message "USB Debugging Connected" when you plugs the USB cable into your computer.
  4. From Eclipse, right-click on the project node ⇒ Run As ⇒ Android Application.
  5. The "Android Device Chooser" dialog appears. Select your real device (instead of the AVD emulator) ⇒ OK.
  6. Eclipse ADT installs the app on the connected device and starts it.
You can also use the "adb" (Android Debug Bridge) tool (under "<ANDROID_SDK_HOME>\platform-tools") to install the ".apk" file ("HelloAndroid.apk") onto the real devices:
// Change directory to <project-root>\bin, where the ".apk" is located
// -d option for real device
> adb -d install filename.apk
2402 KB/s (157468 bytes in 0.064s)
        pkg: /data/local/tmp/filename.apk
Success
  
> adb --help

3.2  Hello-world by Coding

Let's continue from the previous example.
Expand the "src" node. Expand the "com.example.helloandroid" package node. Open the "HelloActivity.java", and replace it with the following codes:

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class HelloActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView textView = new TextView(this);   // Construct a TextView UI component
        textView.setText("Hello, from my code!"); // Set the text message for TextView
        setContentView(textView);  // this Activity sets its content to the TextView
    }

}
Run the application by right-clicking the project node ⇒ "Run As" ⇒ "Android Application". You shall see the message "Hello, from my code!".
Dissecting the "HelloActivity.java" - Application, Activity & View
An application could have one or more Activity.
An Activity, which usually has a screen, is a single, focused thing that the user can interact with the applicatoin. The HelloActivity extends the android.app.Activity class, and overrides the onCreate() method. The onCreate() is a call-back method, which will be called by the Android system when the activity is launched.
A View is a UI component (or widget, or control). We construct a TextView (which is a subclass of android.view.View), and set its text message. We then set the content-view of the HelloActivity screen to this TextView.
Android Application Structure
The Android project (under Eclipse ADT) consists of several folders:
  • src: Java Source codes. The Java classes must be kept in a proper package with at least two levels of identifiers (e.g., com.example).
  • res: Resources, including drawable (e.g., images and icons), layout (UI components and layout), values (e.g., locale strings for internationalization).
  • asset: where you store raw files (e.g., configuration, audio and image files).
  • gen: Generated Java codes.
  • bin: Compiled bytecodes (in sub-directory classes), and the ".apk" (Android Package Archive file).
  • AndroidManifest.xml: The manifest to describe this app, such as its activities and services.
  • default.properties: holds various settings for the build system, updated by the ADT.
  • Android 4.1: the build target platform, with link to Android API ("android.jar").
Android Application Descriptor File - "AndroidManifest.xml"
Each Android application has a manifest file named AndroidManifest.xml in the project's root directory. It descibes the application.
For example, our "HelloAndroid" application, with an activity HelloActivity, has the following manifest (generated automatically by the Eclipse ADT):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloandroid"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".HelloActivity"
            android:label="@string/title_activity_hello" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

  • The <manifest> element specifies the package name, version-code and version-name. The version-code is an integer uses by the Android Market to keep track of new version, usually starts at 1. The version-name is a string for your own identification. It is interesting and confusing that two elements are used to identify a version, e.g., Android platform 4.1 has API Level 16.
  • The <manifest> contains one <application> element.
  • The <application> element specifies the icon, label (the application's title) and theme of this application. It contains one ore more <activity> elements.
  • This application has one activity named HelloAndroid. The <activity> element declares its program name (".HelloActivity" where '.' is relative to the package com.example.helloandroid, you can also use fully-qualified name); and label (the activity's screen title). It may contain <intent-filter>.
  • The <intent-filter> declares that this activity is the entry point (android.intent.action.MAIN) of the application. This activity is to be added to the application launcher (android.intent.category.LAUNCHER).

3.3  Hello-world using XML Layout

Instead of writing program codes to create the UI. It is more flexible and recommended to layout your UI components via a descriptive XML layout file. In this way, you don't need to hardcode the views, and you can easily modify the look and feel of the application by editing the XML markups. The programming codes can therefore focus on the business logic. (This is similar to the Model-View-Control (MVC) framework used in web applications where the views are written in JSPs using markups and the controls in Servlets, which are clearly separated. This is also similar to client-side programming where HTML is used for contents, CSS for presentation and JavaScript for programming logic. Again, views, contents and programs are clearly separated).
To improve the performance, the XML files are compiled into binary using the Android Asset Packaging Tool (aapt). The devices store them as binary, and the file is read in binary, instead of converting back to XML.
Let's rewrite our hello-world to use XML layout.
Step 1: Create a New Android Application
Create a new Android project called "HelloAndroidXML". Use "HelloAndroidXML" for the application name and project name, "com.example.helloandroidxml" for package name. Create a "BlankActivity" called "HelloActivity", with layout name "activity_hello" and title "HelloXML".
Step 2: Define the Layout in XML - "res\layout\activity_hello.xml"
Expand the "HelloAndroidXML" project node. Expand the "res" node and "layout" node. Open the "activity_hello.xml". Eclipse provides different views for a XML file: Graphics Layout and XML. Select the "activity_hello.xml" tab (at the bottom of the panel) and study the code:
<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" >
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"
        tools:context=".HelloActivity" />
</RelativeLayout>
The activity_hello.xml file declares a TextView that holds a text string. Instead of hardcoding the string content, a string reference called @string/hello_world is used, with the actual string coded in res/values/strings.xml. This approach is particular useful to support internationalization, as you can customize different strings for different locales.
This activity's uses a "relative layout", where its components are arranged relative to each other. It has width and height matching its parent ("match_parent").
The screen contains a TextView component, with its text obtained from the string reference "@string/hello_world". The TextView component has width and height big enough to hold its content ("wrap_content"), and is centralized horizontally and vertically.
Step 3: Defining String References and Values - "res\values\string.xml"
Expand res/values node. Open strings.xml, and study the code:
<resources>
    <string name="app_name">HelloAndroidXml</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">HelloXML</string>
</resources>
This "string.xml" defines these string references and values:
  • The string reference "hello_world" contains string value of "Hello world!". Change it to "Hello, from XML!".
  • The string reference "app_name" contains the application's name, that you entered when you created the project. This reference is used in "AndroidManifest.xml".
  • The string reference "title_activity_main" contains the activity's title. This reference is also used in "AndroidManifest.xml". Change it to "Hello in XML Layout"
Step 4: The Activity - "HelloActivity.java"
Next, study the "HelloActitivy.java" (right-click on the project ⇒ Expand "src" node ⇒ Expand package node "com.example.helloandriodxml"), as follows:
package com.example.helloandroidxml;
 
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
 
public class HelloActivity extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hello);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_hello, menu);
        return true;
    }
}
The "HelloActivity" sets its content-view to "R.layout.activity_hello", which is mapped to the XML layout file "res\layout\activity_hello.xml" that we have studied earlier.
Step 5: Run the App
Run the application (select "Run As" menu ⇒ "Android Application"). You shall see the new string "Hello, from XML!" and new title "Hello in XML Layout" displayed on the emulator.
Step 6: The Generated Resource Reference Class - "gen\R.java"
The Eclipse ADT automatically generates a "R.java", which keeps track of all the application resources, in "gen" directory as follows:
package com.example.helloandroidxml;
 
public final class R {
    public static final class attr {
    }
    public static final class dimen {
        public static final int padding_large=0x7f040002;
        public static final int padding_medium=0x7f040001;
        public static final int padding_small=0x7f040000;
    }
    public static final class drawable {
        public static final int ic_action_search=0x7f020000;
        public static final int ic_launcher=0x7f020001;
    }
    public static final class id {
        public static final int menu_settings=0x7f080000;
    }
    public static final class layout {
        public static final int activity_hello=0x7f030000;
    }
    public static final class menu {
        public static final int activity_hello=0x7f070000;
    }
    public static final class string {
        public static final int app_name=0x7f050000;
        public static final int hello_world=0x7f050001;
        public static final int menu_settings=0x7f050002;
        public static final int title_activity_hello=0x7f050003;
    }
    public static final class style {
        public static final int AppTheme=0x7f060000;
    }
}
The R.java ("R" stands for resources) indexes all the resources used in this application in the static nested classes such as layout and string. For example, the inner class layout's property activity_hello (R.layout.activity_hello) references res\layout\activity_hello.xml; the inner class string references res\values\strings.xml.

4.  Publishing Your App

To publish your apps on Android Maket/Google Play, you need to sign your app with your digital certificate. (During development, you app is signed using a debug certificate by the Eclipse ADT.)
Signing Android Apps
  1. From Eclipse, right-click on the project ⇒ Export... ⇒ Android ⇒ Export Android Application.
  2. In "Project Checks" dialog ⇒ Next.
  3. In "Keystore selection" ⇒ Create new keystore ⇒ In "Location", enter the filename for the keystore (e.g., keystore.db) ⇒ Set your password for the keystore.
  4. In "Key creation", enter the data ⇒ Finish.
References:
  1. Signing Your Applications @ http://developer.android.com/tools/publishing/app-signing.html.
  2. For keystore management, read JDK documentation on "keytool - Key and Certificate Management Tool".

5.  Using Android Debug Bridge (ADB)

ADB lets you manage the connected real devices and emulator AVDs. ADB actually consists of three parts:
  • A client program called "adb.exe" (kept under the "<ANDROID_SDK_HOME>\platform-tools").
  • A server that that runs on your development machine, which is responsible for communicating between an "adb" client program and the connected real devices or emulator AVDs.
  • The ADB daemon, which runs as a background process on every real device and emulator AVD. The ADB server connects to this daemon for communication.
You can use the "adb" client to install Android apps (in ".apk" format), or copy files between your development machine and real device's internal storage and external SD card.
From a CMD shell, launch the "adb" client program (you need to include the "<ANDROID_SDK_HOME>\platform-tools" in PATH environment variable):
// List the command options
> adb --help
......
 
// List all the devices connected, take note of the device serial number
> adb devices
......
 
// Install app in the device of the given serial number
> adb –s device_id install app_filename.apk
// Install app on real device
> adb -d install app_filename.apk
// Install app on emulator
> adb -e install app_filename.apk
 
// Copy the file from the development machine to the device
> adb push computer_filename sdcard_filename
// Copy the file from the device to development machine
> adb pull sdcard_filename computer_filename

6.  Next?

Continue with the "Android Training" @ http://developer.android.com/training/index.html.
Read the Android "API Guides" @ http://developer.android.com/guide/components/index.html.
Study the Android sample codes (in Android SDK "samples" directory), especially the "API Demos".
To run the sample programs in Eclipse: Select "File" menu ⇒ "New" ⇒ "Project..." ⇒ "Android" ⇒ "Android Sample Project" ⇒ E.g., "API Demos".
To import an existing project:
  1. Select "File" menu ⇒ "New" ⇒ "Project..." ⇒ "Android" ⇒ "Android Project from Existing Code" ⇒ Next.
  2. In "Import Project" dialog, browse and select the desired project from the Android SDK's "samples" (e.g., "ApiDemos"). Check "Copy projects into workspace".
  3. Run the application. Right-click on the project ⇒ "Run As" ⇒ "Android Application".
REFERENCES & RESOURCES
  1. Android SDK @ http://developer.android.com/sdk/index.html.
  2. "Android Training" @ http://developer.android.com/training/index.html.
  3. Android "API Guides" @ http://developer.android.com/guide/components/index.html.
  4. Android Beginners::@ http://technozodiac.blogspot.com
Read More

Increase Traffic By Click

Contact Form

Name

Email *

Message *

Powered By Blogger · Designed By Priyesh Marvi

Receive All Free Updates Via Facebook.