java meetup - 12-03-15 - android development workshop

50
Introduction to Android Development

Upload: kasun-dananjaya-delgolla

Post on 14-Jul-2015

351 views

Category:

Mobile


0 download

TRANSCRIPT

Introduction to Android Development

About Us

Kasun DelgollaSoftware [email protected]

Chathura Dilan Senior Software [email protected]

Inosh PereraSoftware [email protected]

Here's what we gonna discuss

● Introduction to Android OS and Android SDK

● Application Development in general

● Application types – Exploring Google Play

● Environment preparation (Android SDK tools)

● Technological overview - XML, Java etc

● Application framework

● Developing a simple Android app

● Monetization and Publishing process

Introduction to Android OS and Android SDK

● Android – A Linux based OS designed for touch screen mobile devices.

● It was initially developed by Android Inc, and later in 2005, Google bought android.

● Android came into play in 2007 with the founding of OHA (Open Handset Alliance) which is a consortium of 84 firms (Samsung, LG, Sony, HTC, Dell, Intel, Motorola, Qualcomm, T-Mobile, Nvidia etc) to develop open standards for mobile devices.

● The first Android-powered phone, T-Mobile G1 was sold in October 2008.

● Android is open source and Google releases the code under the Apache License.

● Each major release is named in alphabetical order after a dessert or sugary treat; for example, version 1.5 Cupcake was followed by 1.6 Donut.

Founders

Irina Blok

Android Versions

2015

Now...

● Android is the world's most popular mobile platform.

● It's powerful specially because of Google product support (Ex: Searching, Navigation, G+, Play Store, You Tube, Drive, Gmail,Calendar etc...)

● Multi-tasking

● Widgets

● Notifications

● Voice Typing and Actions

● Photos and videos

● High-end devices

Application Development in General

● We can define Android Application Development in 5 Stages

– Come up with a fantastic concept

– Design the App – Including a cool UI

– Develop the Application

– Publish on Google Play

– EARN :)

Application types – Exploring Google Play

● Within 600,000+ apps and games available on Google Play, we can find Apps which fall into following categories

– Business

– Communication

– Entertainment

– Games

– Health and Fitness

– Media

– Lifestyle

– Books

– Finance

– News & Magazines

– Shopping

– Photography and many more...

Interface & Applications

● Android's user interface is based on direct manipulation, using touch inputs that loosely correspond to real-world actions, like swiping, tapping, pinching and reverse pinching to manipulate on-screen objects.

● Internal hardware such as accelerometers, gyroscopes and proximity sensors are used by some applications to respond to additional user actions.

● Android devices boot to the homescreen, the primary navigation and information point on the device, which is similar to the desktop found on PCs.

● Google offers the Google Play service in which programmers can offer their Android application to Android users. Google phones include the Google Play application which allows to install applications.

● There are more than 600,000 apps and games available on Google Play.

Android Framework

Let's get started :)

● Android SDK - Contains the necessary tools to create, compile and package Android application. It also provides an Android device emulator and the Android debug bridge (adb) tool which allows to connect to an virtual or real Android device.

● Android Development Tools (ADT) -

– Set of components (plug-ins) which comes packed with android studio/extend the Eclipse IDE with Android development capabilities.

– It contains all required functionalities to create, compile, debug and deploy Android applications from the Eclipse IDE.

– ADT also allows to create and start AVDs.

– Provides specialized editors for resources files, e.g. layout files. These editors allow to switch between the XML representation of the file and a richer user interface via tabs on the bottom of the editor.

● Dalvik Virtual Machine - The Android system uses a special virtual machine, i.e. the Dalvik Virtual Machine to run Java based applications. Dalvik uses an own bytecode format which is different from Java bytecode. Therefore you cannot directly run Java class files on Android, they need to get converted in the Dalvik bytecode format.

How an APK is built

● Android applications are primarily written in the Java programming language.

● The Java source files are converted to Java class files by the Java compiler.

● The Android SDK contains a tool called dx which converts Java class files into a .dex (Dalvik Executable) file.

● All class files of one application are placed in one compressed .dex file.

● During this conversion process redundant information in the class files are optimized in the .dex file. For example if the same String is found in different class files, the .dex file contains only once reference of this String.

● The .dex file and the resources of an Android project, e.g. the images and XML files, are packed into an .apk (Android Package) file. The program aapt (Android Asset Packaging Tool) performs this packaging.

● The resulting .apk file contains all necessary data to run the Android application and can be deployed to an Android device via the adb tool.

Android Security Concept

● During deployment on an Android device, the Android system will create a unique user and group ID for every Android application.

● Each Android application will be started in its own process.

● Every android application is isolated from other running applications.

● If data should be shared, application should do that explicitly (Using content provider or services).

Android Permission Concept

● Android predefines permissions for certain tasks but every application can define additional permissions.

● An Android application declare its required permissions in its AndroidManifest.xml configuration file.

● In most cases the requested permissions will be presented to the user before installation of the application. The user needs to decide if these permissions are given to the application.

Application Components

● An Android application consists out of different Android components and additional resources. Each type serves a distinct purpose and has a distinct life-cycle that defines how the component is created and destroyed.

➢ Activities

➢ Services

➢ Broadcast receiver

➢ Content provider

Activity Lifecycle

Find the device location

● LocationManager● FusedLocationApi (Via GoogleAPIClient)

1. Import Google Play Services library

2. Update manifest with permissions and Google play services meta tag

● Add code related to location API to your activity.1. Implement the class from ConnectionCallbacks, OnConnectionFailedListener.

2. Check for availability of Google Play Services by calling checkPlayServices() in onResume().

3. Connect to Google API client by calling mGoogleApiClient.connect() in onStart() method. By calling this, onConnectionFailed(), onConnected() and onConnectionSuspended() will be triggered depending upon the connection status.

4. Once Google API is successfully connected, displayLocation() should be called in onConnected() method to get the current location.

5. Make sure that the WIFI and location is enabled on your device before you test.

● If you need periodic location updates, you can implement a LocationListener.

Getting Started with Android Development

What do you need?

● Computer● JDK● Android Studio● Internet● Android SDK tools● Android Platform tools● Android Build tools● Idea?

Weather App (Kälagune)

● GitHub: https://github.com/chaturadilan/Kalagune

● Download Images : http://bit.ly/1KZ8h1h

● Backend Service: http://www.dilan.me/apps/weather/api.php

Resources

Android Activity

An activity is a single, focused thing that the user can do. It is simply an user interface.

Activity Lifecycle

App Manifest

● Every application must have an AndroidManifest.xml

● manifest file presents essential information about your app to the Android system

Android Plug-in for Gradle

Gradle

● Advanced build toolkit that manages dependencies● define custom build logic● Uses Groovy Syntax● Android Studio uses a Gradle wrapper● Android plugin for Gradle also runs independent of

Android Studio● The build configuration for your project is defined inside

build.gradle

Configuring Gradle Builds

Declare dependencies

dependencies {

// Module dependency

compile project(":lib")

// Remote binary dependency

compile 'com.android.support:appcompat-v7:19.0.1'

// Local binary dependency

compile fileTree(dir: 'libs', include: ['*.jar'])

}

Build variants

● Build variants are combinations of product flavors and build types

● Product flavors represent product build versions of an app, such as free and paid.

● Build types represent the build packaging versions generated for each app package, such as debug and release.

● The build system generates APKs for each combination of product flavor and build type.

AppCompat

● Enables you to bring your latest designs to older Android platforms

dependencies {

compile "com.android.support:appcompat-v7:21.0.+"

}

Android Layouts

● Relative Layout - Enables you to specify the location of child objects relative to each other

● Linear Layout - A layout that organizes its children into a single horizontal or vertical row.

Home Activity Views

● Time - id = textViewTime, size = 36sp

● Date - id = textViewDate, size = 18sp

● Image - id = imageViewWeather, height/width= 200dp

● Weather - id = textViewWeather, size = 18sp

● Temp - id = textViewTemp, size = 64sp

● City - id = textViewCity, size = 36sp

Screen Densities

● ldpi (low) ~120dpi● mdpi (medium) ~160dpi● hdpi (high) ~240dpi● xhdpi (extra-high) ~320dpi● xxhdpi (extra-extra-high) ~480dpi● xxxhdpi (extra-extra-extra-high) ~640dpi

Range of screens supported

xlarge screens are at least 960dp x 720dp

large screens are at least 640dp x 480dp

normal screens are at least 470dp x 320dp

small screens are at least 426dp x 320dp

Multiple Layouts Files

● res/layout/main_activity.xml

# For handsets (smaller than 600dp available width)

● res/layout-sw600dp/main_activity.xml

# For 7” tablets (600dp wide and bigger)

● res/layout-sw720dp/main_activity.xml

# For 10” tablets (720dp wide and bigger)

Fragments

● A Fragment represents a behavior or a portion of user interface in an Activity

● Fragments has it's own life cycles● A fragment must always be embedded in an

activity

Adapter

● The Adapter provides access to the data items.● Adapter is also responsible for making a View

for each item in the data set

Checking out the source from Github

● https://github.com/chaturadilan/Kalagune

Monetization of Applications

● Google Admob● Dialog In-App Purchase Android SDK

Monetize without Compromising User Experience

w

Preparing Application for Release

● keytool -genkey -v -keystore <filename>.keystore -alias <key-name> -keyalg RSA -keysize 2048 -validity 10000

Publishing Android app in Google Play

● A developer account must be created. $25● All applications need to be signed with a

cryptographic key that expires after October 22, 2033.

● Maximum size for an APK published on Google Play is 50MB or use APK Expansions

Google Play Developer Console

Upload new apk

Upload Assets

Resources

● http://www.androidhive.info/2015/02/android-location-api-using-google-play-services/● http://developer.android.com/training/index.html● http://www.vogella.com/android.html● http://www.tutorialspoint.com/android/

Thank you!