Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Android programming in java, Study notes of Mobile Computing

tutorials on android programming in java

Typology: Study notes

2016/2017

Uploaded on 09/10/2017

aayush-srivastava
aayush-srivastava 🇮🇳

5

(2)

2 documents

1 / 836

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cover page
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

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 & DisclaimerCopyright 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 ··························································································································
    1. 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 ·························································································································
    1. ORGANIZING & ACCESSING THE RESOURCES ········································································
    • Organize Resources ·································································································································
    • Alternative Resources ·····························································································································
    • Accessing Resources ·······························································································································
    • Accessing Resources in Code ···················································································································
    • Accessing Resources in XML ····················································································································
    1. ACTIVITIES ·····························································································································
    1. SERVICES ·······························································································································
    1. BROADCAST RECEIVERS·········································································································
    • Creating the Broadcast Receiver ·············································································································
    • Registering Broadcast Receiver ···············································································································
    • Broadcasting Custom Intents ··················································································································
    1. CONTENT PROVIDERS ·········································································································
    • Content URIs ··········································································································································· iv
    • Create Content Provider ·························································································································
    1. FRAGMENTS ························································································································
    • Fragment Life Cycle ·································································································································
    • How to use Fragments? ··························································································································
    1. INTENTS & FILTERS ··············································································································
    • Intent Objects ·········································································································································
    • Action ·····················································································································································
    • Data ························································································································································
    • Category ·················································································································································
    • Extras ······················································································································································
    • Flags························································································································································
    • Component Name ···································································································································
    • Types of Intents ······································································································································
    • Explicit Intents ········································································································································
    • Implicit Intents ········································································································································
    • Intent Filters ···········································································································································
    1. UI LAYOUTS ·······················································································································
    • Android Layout Types ···························································································································
    • Layout Attributes ··································································································································
    • View Identification································································································································
    1. UI CONTROLS ····················································································································
    • Android UI Controls ······························································································································
    • Create UI Controls ·································································································································
    1. 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: ················································································································································
    1. STYLES & THEMES ·············································································································
    • Defining Styles ······································································································································
    • Using Styles···········································································································································
    • Style Inheritance ···································································································································
    • Android Themes····································································································································
    • Default Styles & Themes ·······················································································································
    1. 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····················································································································································
    1. DRAG & DROP ···················································································································
    • The Drag/Drop Process ·························································································································
    • The DragEvent Class ······························································································································
      • Constants ···············································································································································
      • Methods ·················································································································································
    • Listening for Drag Event ························································································································
    • Starting a Drag Event ····························································································································
    1. 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 ····························································································································
    1. 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 ···················································································································
    1. SENDING EMAIL ················································································································
    • Intent Object - Action to send Email ·····································································································
    • Intent Object - Data/Type to send Email ·······························································································
    • Intent Object - Extra to send Email········································································································
    1. 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 ·········································································································
    1. PHONE CALLS ····················································································································
    • Intent Object - Action to make Phone Call ····························································································
    • Intent Object - Data/Type to make Phone Call ······················································································ vii
    1. PUBLISHING ANDROID APPLICATION ················································································
    • Export Android Application ···················································································································
    • Google Play Registration ·······················································································································
    1. ALERT DIALOG TUTORIAL ··································································································
    1. ANIMATIONS ····················································································································
    • Tween Animation··································································································································
    • Zoom in animation ································································································································
    1. AUDIO CAPTURE ···············································································································
    1. AUDIO MANAGER ·············································································································
    1. AUTOCOMPLETE ···············································································································
    1. BEST PRACTICES ···············································································································
    • Best Practices - User input ····················································································································
      • AsyncTask Vs Services. ···························································································································
    • Best Practices - Performance ················································································································
    • Best Practices - Security and privacy ·····································································································
    1. BLUETOOTH ·····················································································································
    1. CAMERA ····························································································································
    • Using existing android camera application in our application ·······························································
    • Directly using Camera API Provided by Android in our Application ·······················································
    1. CLIPBOARD ·······················································································································
    • Copying data ·········································································································································
    • Pasting data ··········································································································································
    1. CUSTOM FONTS ···············································································································
    1. 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 ·································································································
    1. 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 ·······································································································································
    1. EMULATOR························································································································
    • Creating AVD ········································································································································
    • Creating Snapshots ·······························································································································
    • Changing Orientation ····························································································································
    • Emulator Commands. ···························································································································
    • Emulator - Sending SMS ························································································································
      • Sending SMS through Telnet. ·················································································································
    • Emulator - Making Call ··························································································································
    • Emulator - Transferring files ··················································································································
    1. FACEBOOK INTEGRATION··································································································
    • Integrating Facebook SDK ·····················································································································
      • Generating application signature ···········································································································
      • Registering your application ··················································································································
      • Downloading SDK and integrating it ······································································································ ix
      • Creating facebook login application ·······································································································
    • Intent share ··········································································································································
    1. GESTURES ························································································································
    • Handling Pinch Gesture ·························································································································
    1. 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. ·····························································································
    1. IMAGE EFFECTS ················································································································
    1. IMAGE SWITCHER ············································································································
    1. INTERNAL STORAGE ··········································································································
    • Writing file ············································································································································
    • Reading file ···········································································································································
    1. JETPLAYER ·························································································································
    • Using JetCreator····································································································································
      • Installing python····································································································································· x
      • Installing WxPython ·······························································································································
      • Running JetCreator·································································································································
      • Creating JetContent ·······························································································································
    • Verifying Results ···································································································································
    1. JSON PARSER ····················································································································
    • JSON - Elements ····································································································································
    • JSON - Parsing ·······································································································································
    1. LINKEDIN INTEGRATION ···································································································
    • Integrating LinkedIn SDK ·······················································································································
      • Registering your application ··················································································································
      • Downloading SDK and integrating it ······································································································
      • Posting updates on LinkedIn application ·······························································································
    • Intent share ··········································································································································
    1. LOADING SPINNER ···········································································································
    1. LOCALIZATION ··················································································································
    • Localizing Strings ···································································································································
      • Italy, res/values-it/strings.xml ···············································································································
      • Spanish, res/values-it/strings.xml ··········································································································
      • French, res/values-it/strings.xml ···········································································································
    1. LOGIN SCREEN ·················································································································
    1. MEDIA PLAYER ·················································································································
    1. MULTITOUCH ···················································································································
    1. NAVIGATION ····················································································································
    • Providing Up Navigation ·······················································································································
    • Handling device back button ·················································································································
    1. NETWORK CONNECTION ··································································································
    • Checking Network Connection ··············································································································
    • Performing Network Operations ··········································································································· xi
    1. NFC GUIDE ·······················································································································
    • How It Works: ·······································································································································
      • Three Modes of Operation ·····················································································································
    • How it works with Android: ··················································································································
    • Future Applications ·······························································································································
    1. 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 ···········································································································································
    1. PROGRESS CIRCLE ············································································································
    1. PROGRESS BAR USING PROGRESS DIALOG ·······································································
    1. PUSH NOTIFICATION ········································································································
    1. RENDERSCRIPT ·················································································································
    • How RenderScript Works: ·····················································································································
    • How to Begin: ·······································································································································
      • A RenderScript Kernel ····························································································································
      • RenderScript APIs ···································································································································
      • How to use RenderScript Support Library ······························································································
    1. RSS READER ······················································································································
    • RSS Example ·········································································································································
    • RSS Elements ········································································································································
    • Parsing RSS ···········································································································································
    1. SCREEN CAST ···················································································································· xii
    • Screen Cast Steps ··································································································································
      • Step 1 ·····················································································································································
      • Step ························································································································································
      • Step 3 ·····················································································································································
      • Step ························································································································································
      • Step 5 ·····················································································································································
    1. SDK MANAGER ·················································································································
    • Running Android SDK Manager: ············································································································
    • Recommended ······································································································································
    • Enabling Proxy in Android SDK Manager ·······························································································
    • Adding New Third Party Sites ················································································································
    1. SENSORS ··························································································································
    • Getting list of sensors supported. ·········································································································
    1. SESSION MANAGEMENT ··································································································
    • Shared Preferences ·······························································································································
    • Session Management through Shared Preferences ···············································································
    1. SIP PROTOCOL ··················································································································
    • Applications ··········································································································································
    • Requirements ·······································································································································
    • SIP Classes·············································································································································
    • Functions of SIP ····································································································································
    • Components of SIP ································································································································
    • UAC ·······················································································································································
    • UAS ·······················································································································································
    • SipManager···········································································································································
    1. SPELLING CHECKER ··········································································································
    1. SQLITE DATABASE ············································································································ xiii
    • Database - Package ·······························································································································
    • Database - Creation ······························································································································
    • Database - Insertion ······························································································································
    • Database - Fetching ······························································································································
    • Database - Helper class ·························································································································
    1. SUPPORT LIBRARY ············································································································
    • Support Library Features·······················································································································
    • Downloading the Support Libraries ·······································································································
      • Choosing Support Libraries ····················································································································
      • Changes in Android.Manifest ·················································································································
      • API Version ·············································································································································
    1. TESTING ···························································································································
    • Test Structure ·······································································································································
    • Testing Tools in Android ·······················································································································
    • JUnit ·····················································································································································
    • Monkey·················································································································································
      • Monkey features ····································································································································
      • Monkey Usage········································································································································
    1. TEXT TO SPEECH ···············································································································
    1. TEXTURE VIEW ·················································································································
    1. TWITTER INTEGRATION ····································································································
    • Integrating Twitter SDK ·························································································································
      • Registering your application ··················································································································
      • Downloading SDK and integrating it ······································································································
      • Posting tweets on twitter application ····································································································
    • Intent share ··········································································································································
    1. 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 ································································································································
    1. 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)·········································································································
    1. UI TESTING ························································································································
    • uiautomatorviewer ·······························································································································
    • uiautomator··········································································································································
    1. WEBVIEW ·························································································································
    1. WI-FI ································································································································
    1. WIDGETS ··························································································································
    • Widget - XML file ··································································································································
    • Widget - Layout file ·······························································································································
    • Widget - Java file··································································································································· xv
    • Widget - Manifest file ···························································································································
    1. 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