Download Android programming in java and more Study notes Mobile Computing in PDF only on Docsity!
Cover page
i
About the Tutorial
Android is an open-source, 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 tutorial will teach you the basic Android programming and will also take you
through some advance concepts related to Android application development.
Audience
This tutorial has been prepared for 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.
Prerequisites
Android programming is based on Java programming language. If you have a
basic understanding of Java programming, then it will be fun to learn Android
application development.
Copyright & Disclaimer Copyright 2014 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely
as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I)
Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@tutorialspoint.com
iii
- Broadcast Receivers ································································································································
- Content Providers ···································································································································
- Additional Components ··························································································································
- HELLO WORLD EXAMPLE·······································································································
- Create Android Application ·····················································································································
- Anatomy of Android Application·············································································································
- The Main Activity File ·····························································································································
- The Manifest File ····································································································································
- The Strings File ········································································································································
- The R File ················································································································································
- The Layout File ········································································································································
- Running the Application ·························································································································
- ORGANIZING & ACCESSING THE RESOURCES ········································································
- Organize Resources ·································································································································
- Alternative Resources ·····························································································································
- Accessing Resources ·······························································································································
- Accessing Resources in Code ···················································································································
- Accessing Resources in XML ····················································································································
- ACTIVITIES ·····························································································································
- SERVICES ·······························································································································
- BROADCAST RECEIVERS·········································································································
- Creating the Broadcast Receiver ·············································································································
- Registering Broadcast Receiver ···············································································································
- Broadcasting Custom Intents ··················································································································
- CONTENT PROVIDERS ·········································································································
- Content URIs ··········································································································································· iv
- Create Content Provider ·························································································································
- FRAGMENTS ························································································································
- Fragment Life Cycle ·································································································································
- How to use Fragments? ··························································································································
- INTENTS & FILTERS ··············································································································
- Intent Objects ·········································································································································
- Action ·····················································································································································
- Data ························································································································································
- Category ·················································································································································
- Extras ······················································································································································
- Flags························································································································································
- Component Name ···································································································································
- Types of Intents ······································································································································
- Explicit Intents ········································································································································
- Implicit Intents ········································································································································
- Intent Filters ···········································································································································
- UI LAYOUTS ·······················································································································
- Android Layout Types ···························································································································
- Layout Attributes ··································································································································
- View Identification································································································································
- UI CONTROLS ····················································································································
- Android UI Controls ······························································································································
- Create UI Controls ·································································································································
- EVENT HANDLING ·············································································································
- Event Listeners & Event Handlers ········································································································· v
- Event Listeners Registration: ·················································································································
- Event Handling Examples ······················································································································
- Event Listeners Registration Using an Anonymous Inner Class ·····························································
- Registration Using the Activity Implements Listener Interface ······························································
- Registration Using Layout file activity_main.xml ··················································································
- Exercise: ················································································································································
- STYLES & THEMES ·············································································································
- Defining Styles ······································································································································
- Using Styles···········································································································································
- Style Inheritance ···································································································································
- Android Themes····································································································································
- Default Styles & Themes ·······················································································································
- CUSTOM COMPONENTS ···································································································
- Creating a Simple Custom Component ··································································································
- Instantiate using code inside activity class ····························································································
- Instantiate using Layout XML file ··········································································································
- Custom Component with Custom Attributes ························································································
- Step 1····················································································································································
- Step 2····················································································································································
- Step 3····················································································································································
- DRAG & DROP ···················································································································
- The Drag/Drop Process ·························································································································
- The DragEvent Class ······························································································································
- Constants ···············································································································································
- Methods ·················································································································································
- Listening for Drag Event ························································································································
- Starting a Drag Event ····························································································································
- NOTIFICATIONS ················································································································· vi
- Create and Send Notifications ···············································································································
- Step 1 - Create Notification Builder ·······································································································
- Step 2 - Setting Notification Properties ·································································································
- Step 3 - Attach Actions ···························································································································
- Step 4 - Issue the notification ················································································································
- The NotificationCompat.Builder Class ···································································································
- Big View Notification ····························································································································
- LOCATION-BASED SERVICES ······························································································
- The Location Object ······························································································································
- Get the Current Location·······················································································································
- Get the Updated Location ·····················································································································
- Location Quality of Service ···················································································································
- Displaying a Location Address ···············································································································
- Install the Google Play Services SDK······································································································
- Create Android Application ···················································································································
- SENDING EMAIL ················································································································
- Intent Object - Action to send Email ·····································································································
- Intent Object - Data/Type to send Email ·······························································································
- Intent Object - Extra to send Email········································································································
- SENDING SMS ···················································································································
- Using SmsManager to send SMS ···········································································································
- Using Built-in Intent to send SMS ··········································································································
- Intent Object - Action to send SMS ·······································································································
- Intent Object - Data/Type to send SMS ·································································································
- Intent Object - Extra to send SMS ·········································································································
- PHONE CALLS ····················································································································
- Intent Object - Action to make Phone Call ····························································································
- Intent Object - Data/Type to make Phone Call ······················································································ vii
- PUBLISHING ANDROID APPLICATION ················································································
- Export Android Application ···················································································································
- Google Play Registration ·······················································································································
- ALERT DIALOG TUTORIAL ··································································································
- ANIMATIONS ····················································································································
- Tween Animation··································································································································
- Zoom in animation ································································································································
- AUDIO CAPTURE ···············································································································
- AUDIO MANAGER ·············································································································
- AUTOCOMPLETE ···············································································································
- BEST PRACTICES ···············································································································
- Best Practices - User input ····················································································································
- AsyncTask Vs Services. ···························································································································
- Best Practices - Performance ················································································································
- Best Practices - Security and privacy ·····································································································
- BLUETOOTH ·····················································································································
- CAMERA ····························································································································
- Using existing android camera application in our application ·······························································
- Directly using Camera API Provided by Android in our Application ·······················································
- CLIPBOARD ·······················································································································
- Copying data ·········································································································································
- Pasting data ··········································································································································
- CUSTOM FONTS ···············································································································
- DATA BACKUP ·················································································································· viii
- Test your BackupAgent ·························································································································
- Install your application on a suitable Android system image. ·······························································
- Ensure data backup is enabled ··············································································································
- Performing backup ·································································································································
- Uninstall and reinstall your application ·································································································
- DEVELOPER TOOLS ···········································································································
- SDK tools ··············································································································································
- Android ·················································································································································
- DDMS····················································································································································
- Running DDMS ·······································································································································
- How it works ··········································································································································
- Using DDMS ···········································································································································
- Making SMS············································································································································
- Making Call ·············································································································································
- Capturing ScreenShot ···························································································································
- Sqlite3 ···················································································································································
- Use Sqlite3 from a remote shell. ············································································································
- Using Sqlite3 directly······························································································································
- Platform tools ·······································································································································
- EMULATOR························································································································
- Creating AVD ········································································································································
- Creating Snapshots ·······························································································································
- Changing Orientation ····························································································································
- Emulator Commands. ···························································································································
- Emulator - Sending SMS ························································································································
- Sending SMS through Telnet. ·················································································································
- Emulator - Making Call ··························································································································
- Emulator - Transferring files ··················································································································
- FACEBOOK INTEGRATION··································································································
- Integrating Facebook SDK ·····················································································································
- Generating application signature ···········································································································
- Registering your application ··················································································································
- Downloading SDK and integrating it ······································································································ ix
- Creating facebook login application ·······································································································
- Intent share ··········································································································································
- GESTURES ························································································································
- Handling Pinch Gesture ·························································································································
- GOOGLE MAPS ·················································································································
- Adding Google Map ······························································································································
- Google Map - Activity file ·······················································································································
- Google Map - Layout file ························································································································
- Google Map - AndroidManifest file ·······································································································
- Customizing Google Map ······················································································································
- Adding Marker ·······································································································································
- Changing Map Type································································································································
- Enable/Disable zoom ·····························································································································
- Integrating Google Maps·······················································································································
- Download and configure. Google Play Services SDK ··············································································
- Install Google services SDK ····················································································································
- Import SDK to eclipse ·····························································································································
- Configure your project with SDK ············································································································
- Obtaining the API key ···························································································································
- Getting Certificate from KeyTool ···········································································································
- Getting key from Google Console ··········································································································
- Specify Android Manifest Settings ········································································································
- Adding Google Maps to your application. ·····························································································
- IMAGE EFFECTS ················································································································
- IMAGE SWITCHER ············································································································
- INTERNAL STORAGE ··········································································································
- Writing file ············································································································································
- Reading file ···········································································································································
- JETPLAYER ·························································································································
- Using JetCreator····································································································································
- Installing python····································································································································· x
- Installing WxPython ·······························································································································
- Running JetCreator·································································································································
- Creating JetContent ·······························································································································
- Verifying Results ···································································································································
- JSON PARSER ····················································································································
- JSON - Elements ····································································································································
- JSON - Parsing ·······································································································································
- LINKEDIN INTEGRATION ···································································································
- Integrating LinkedIn SDK ·······················································································································
- Registering your application ··················································································································
- Downloading SDK and integrating it ······································································································
- Posting updates on LinkedIn application ·······························································································
- Intent share ··········································································································································
- LOADING SPINNER ···········································································································
- LOCALIZATION ··················································································································
- Localizing Strings ···································································································································
- Italy, res/values-it/strings.xml ···············································································································
- Spanish, res/values-it/strings.xml ··········································································································
- French, res/values-it/strings.xml ···········································································································
- LOGIN SCREEN ·················································································································
- MEDIA PLAYER ·················································································································
- MULTITOUCH ···················································································································
- NAVIGATION ····················································································································
- Providing Up Navigation ·······················································································································
- Handling device back button ·················································································································
- NETWORK CONNECTION ··································································································
- Checking Network Connection ··············································································································
- Performing Network Operations ··········································································································· xi
- NFC GUIDE ·······················································································································
- How It Works: ·······································································································································
- Three Modes of Operation ·····················································································································
- How it works with Android: ··················································································································
- Future Applications ·······························································································································
- PHP/MYSQL ······················································································································
- PHP - MYSQL ·········································································································································
- Creating Database ··································································································································
- Creating Tables ·······································································································································
- Inserting Values in tables ·······················································································································
- PHP - GET and POST methods ················································································································
- Android - Connecting MYSQL ················································································································
- Connecting Via Get Method ···················································································································
- Connecting Via Post Method ·················································································································
- PHP - MYSQL part ···································································································································
- Android Part ···········································································································································
- PROGRESS CIRCLE ············································································································
- PROGRESS BAR USING PROGRESS DIALOG ·······································································
- PUSH NOTIFICATION ········································································································
- RENDERSCRIPT ·················································································································
- How RenderScript Works: ·····················································································································
- How to Begin: ·······································································································································
- A RenderScript Kernel ····························································································································
- RenderScript APIs ···································································································································
- How to use RenderScript Support Library ······························································································
- RSS READER ······················································································································
- RSS Example ·········································································································································
- RSS Elements ········································································································································
- Parsing RSS ···········································································································································
- SCREEN CAST ···················································································································· xii
- Screen Cast Steps ··································································································································
- Step 1 ·····················································································································································
- Step ························································································································································
- Step 3 ·····················································································································································
- Step ························································································································································
- Step 5 ·····················································································································································
- SDK MANAGER ·················································································································
- Running Android SDK Manager: ············································································································
- Recommended ······································································································································
- Enabling Proxy in Android SDK Manager ·······························································································
- Adding New Third Party Sites ················································································································
- SENSORS ··························································································································
- Getting list of sensors supported. ·········································································································
- SESSION MANAGEMENT ··································································································
- Shared Preferences ·······························································································································
- Session Management through Shared Preferences ···············································································
- SIP PROTOCOL ··················································································································
- Applications ··········································································································································
- Requirements ·······································································································································
- SIP Classes·············································································································································
- Functions of SIP ····································································································································
- Components of SIP ································································································································
- UAC ·······················································································································································
- UAS ·······················································································································································
- SipManager···········································································································································
- SPELLING CHECKER ··········································································································
- SQLITE DATABASE ············································································································ xiii
- Database - Package ·······························································································································
- Database - Creation ······························································································································
- Database - Insertion ······························································································································
- Database - Fetching ······························································································································
- Database - Helper class ·························································································································
- SUPPORT LIBRARY ············································································································
- Support Library Features·······················································································································
- Downloading the Support Libraries ·······································································································
- Choosing Support Libraries ····················································································································
- Changes in Android.Manifest ·················································································································
- API Version ·············································································································································
- TESTING ···························································································································
- Test Structure ·······································································································································
- Testing Tools in Android ·······················································································································
- JUnit ·····················································································································································
- Monkey·················································································································································
- Monkey features ····································································································································
- Monkey Usage········································································································································
- TEXT TO SPEECH ···············································································································
- TEXTURE VIEW ·················································································································
- TWITTER INTEGRATION ····································································································
- Integrating Twitter SDK ·························································································································
- Registering your application ··················································································································
- Downloading SDK and integrating it ······································································································
- Posting tweets on twitter application ····································································································
- Intent share ··········································································································································
- UI DESIGN ························································································································
- UI screen components ··························································································································
- Understanding Screen Components ······································································································ xiv
- View and ViewGroups ····························································································································
- Types of layout ·······································································································································
- Linear Layout ··········································································································································
- AbsoluteLayout ······································································································································
- TableLayout ············································································································································
- RelativeLayout········································································································································
- FrameLayout ··········································································································································
- Units of Measurement ··························································································································
- Screen Densities····································································································································
- Optimizing layouts ································································································································
- UI PATTERNS ····················································································································
- UI Patterns components ·······················································································································
- Action Bar ·············································································································································
- Action Bar Components ·························································································································
- Confirming and Acknowledging ············································································································
- Confirming··············································································································································
- Acknowledging ·······································································································································
- Settings ·················································································································································
- Placement of Settings ····························································································································
- Help ······················································································································································
- Placement of Help ··································································································································
- Selection ···············································································································································
- Using Contextual Action Bar (CAB)·········································································································
- UI TESTING ························································································································
- uiautomatorviewer ·······························································································································
- uiautomator··········································································································································
- WEBVIEW ·························································································································
- WI-FI ································································································································
- WIDGETS ··························································································································
- Widget - XML file ··································································································································
- Widget - Layout file ·······························································································································
- Widget - Java file··································································································································· xv
- Widget - Manifest file ···························································································································
- XML PARSER ·····················································································································
- XML - Elements ·····································································································································
- XML - Parsing ········································································································································
Android
What is Android?
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.
Android offers a unified approach to application development for mobile devices
which means developers need to develop only for Android, and their applications
should be able to run on different devices powered by Android.
The first beta version of the Android Software Development Kit (SDK) was
released by Google in 2007, whereas the first commercial version, Android 1.0,
was released in September 2008.
On June 27, 2012, at the Google I/O conference, Google announced the next
Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the
primary aim of improving the user interface, both in terms of functionality and
performance.
The source code for Android is available under free and open source software
licenses. Google publishes most of the code under the Apache License version
2.0 and the rest, Linux kernel changes, under the GNU General Public License
version 2.
Features of Android
Android is a powerful operating system competing with Apple 4GS and support
great features. Few of them are listed below:
Feature Description
Beautiful UI Android OS basic screen provides a beautiful and intuitive
user interface.
Connectivity GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi,
LTE, NFC and WiMAX.
Storage SQLite, a lightweight relational database, is used for data
storage purposes.
1. OVERVIEW
Android
and is growing fast. Every day more than 1 million new Android devices are
activated worldwide.
This tutorial has been written with an aim to teach you how to develop and
package Android application. We will start from environment setup for Android
application programming and then drill down to look into various aspects of
Android applications.
Android
You will be glad to know that 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.
Second point is that all the required tools to develop Android applications are
freely available and can be downloaded from the Web. Following is the list of
software's you will need before you start your Android application programming.
Java JDK5 or JDK
Android SDK
Eclipse IDE for Java Developers (optional)
Android Development Tools (ADT) Eclipse Plugin (optional)
Here last two components are optional and if you are working on Windows
machine then these components make your life easy while doing Java based
application development. So let us have a look at how to proceed to set the
required environment.
Step 1 - Setup Java Development Kit (JDK)
You can download the latest version of Java JDK from Oracle's Java site: Java SE
Downloads. You will find instructions for installing JDK in downloaded files, follow
the given instructions to install and configure the setup. Finally, set PATH and
JAVA_HOME environment variables to refer to the directory that
contains java and javac , typically java_install_dir/bin and java_install_dir
respectively.
If you are running Windows and have installed the JDK in C:\jdk1.6.0_15, you
would have to put the following line in your C:\autoexec.bat file.
set PATH=C:\jdk1.6.0_15\bin;%PATH%
set JAVA_HOME=C:\jdk1.6.0_
Alternatively, you could also right-click on My Computer , select Properties ,
then Advanced , then Environment Variables. Then, you would update the PATH
value and press the OK button.
On Linux, if the SDK is installed in /usr/local/jdk1.6.0_15 and you use the C
shell, you would put the following code into your .cshrc file.
2. ENVIORNMENT SETUP