Introduction to Android
1.4 Android Operating System
1.4.7 Android 5.0 and 5.1 (Lollipop)
Android Lollipop—released in November 2014—was a major update with thousands of API enhancements for phones and tablets, and new capabilities that enable developers to create apps for wearables (e.g., smart watches), TVs and cars. One of the biggest changes was material design—a complete user-interface redesign (also used in Google’s web apps). Other features included: a new Android runtime, notification enhancements (enabling us- ers to interact with a notification without leaving the current app), networking enhance- ments (Bluetooth, Wi-Fi, cellular and NFC), high-performance graphics (OpenGL ES 3.1 and the Android Extension Pack), better audio capabilities (capture, multichannel mixing, playback and support for USB peripherals), enhanced camera capabilities, screen sharing, new sensor support, enhanced accessibility features, multiple SIM card support and more. Figure 1.9 lists some of the key Lollipop features. For a complete list, see
Feature Description
Immersive mode The status bar at the top of the screen and the menu buttons at the bot- tom can be hidden, allowing your apps to fill more of the screen. Users can access the status bar by swiping down from the top of the screen, and the system bar (with the back button, home button and recent apps but- ton) by swiping up from the bottom.
Printing framework Build printing functionality into your apps, including locating available printers over Wi-Fi or the cloud, selecting the paper size and specifying which pages to print.
Storage access framework
Create document storage providers that allow users to browse, create and edit files (e.g., documents and images) across multiple apps.
SMS provider Create SMS (Short Message Service) or MMS (Multimedia Messaging Service) apps using the new SMS provider and APIs. Users can now select their default messaging app.
Transitions framework The new framework makes it easier to create transition animations. Screen recording Record video of your app to create tutorials and marketing materials. Enhanced accessibility The captioning manager API allows apps to check the user's captioning
preferences (e.g., language, text styles and more).
Chromium WebView Supports the latest standards for displaying web content including HTML5, CSS3 and a faster version of JavaScript.
Step detector and step counter
Create apps that detect whether the user is running, walking or climbing stairs and count the number of steps.
Host Card Emulator (HCE)
HCE enables any app to perform secure NFC transactions (e.g., mobile payments) without the need for a secure element on the SIM card con- trolled by the wireless carrier.
Fig. 1.8 | Some Android KitKat features (http://developer.android.com/about/ versions/kitkat.html).
http://developer.android.com/about/versions/lollipop.html http://developer.android.com/about/versions/android-5.0.html http://developer.android.com/about/versions/android-5.1.html
ptg16518503
1.4.8 Android 6 (Marshmallow)
Android Marshmallow, released in September 2015, is the current version of Android at the time of this writing. Some new features include Now on Tap (for getting Google Now information in the context of an app), Doze and App Standby (for saving battery), a new permissions model to make apps easier to install, fingerprint authentication, better data protection, better text-selection support, 4K display support, new audio and video capa- bilities, new camera capabilities (flashlight and image-reprocessing APIs) and more. Figure 1.10 lists some of the key Lollipop features. For a complete list, see
Feature Description
Material design Google’s new look-and-feel for Android and web applications was the key new feature in Lollipop. Material design helps you create apps with nice transition effects, shadows that add depth to the user interface and empha- size actionable components, customization capabilities and more. For details, visit https://www.google.com/design/spec/material-design/ introduction.html.
ART runtime Google replaced the original Android runtime with the new 64-bit com- patible ART runtime, which uses a combination of interpretation, ahead- of-time (AOT) compilation and just-in-time (JIT) compilation to improve performance.
Concurrent docu- ments and activi- ties in the recent apps screen
Apps can now specify that multiple activities and documents should appear on the recent apps screen. For example, if the user has multiple tabs open in a web browser or multiple documents open in a text-editing app, when the user touches the recent apps button ( ), each browser tab or document can appear as a separate item that the user can select. Screen capturing and
sharing
Apps can now capture the device’s screen and share the contents with other users across a network.
Project Volta Features that help preserve battery life, including the new JobScheduler
that can execute asynchronous tasks when the device is charging, con- nected to an unmetered network (i.e., use Wi-Fi vs. cellular data) or idle.
Fig. 1.9 | Some Android Lollipop features (http://developer.android.com/about/ versions/lollipop.html).
http://developer.android.com/about/versions/marshmallow/android- 6.0-changes.html
Feature Description
Doze Using software and sensors, Android determines when a device is station- ary for a period of time—such as when you place it on a table overnight— and defers background processes that drain the battery.
Fig. 1.10 | Some Android Marshmallow features (http://developer.android.com/about/ versions/marshmallow/android-6.0-changes.html). (Part 1 of 2.)
ptg16518503
1.5 Downloading Apps from Google Play 13
1.5
Downloading Apps from Google Play
At the time of this writing, there were over 1.6 million apps in Google Play, and the num- ber is growing quickly.8 Figure 1.11 lists some popular free and fee-based apps in various categories. You can download apps through the Play Store app installed on your Android device. You also can log into your Google Play account at
then specify the Android device on which to install the app. It will then download via the device’s Wi-Fi or 3G/4G connection. In Chapter 10, Google Play and App Business Is- sues, we discuss additional app stores, offering your apps for free or charging a fee, app pricing and more.
App Standby For apps that a user has open but has not interacted with recently, Android defers background network activity.
Now on Tap Tap and hold the home button while inside any app and Google Now inspects what’s on the screen and presents relevant information in the form of cards. For example, in a text message discussing a movie, a card containing information about that movie is displayed. Similarly, in a text message mentioning a restaurant name, a card with the ratings, location and phone number appears.
New permissions model
Before Android 6.0, a user was required at installation time to grant in advance all permissions that an app would ever need—this caused many people not to install certain apps. With the new model, the app is installed without asking for any permissions. Instead, the user is asked to grant a permission only the first time the corresponding feature is used. Fingerprint authenti-
cation
For devices with fingerprint readers, apps can now authenticate users via their fingerprints.
App linking Enables developers to associate apps with their own web domains and craft web links that launch specific apps from the same developer. Automatic backup Android can automatically backup and restore an app’s data.
Direct Share You can define direct share targets in your app that enable users to share data via other apps, directly from your app.
Voice Interaction API Enables apps to respond to voice interactions. Bluetooth stylus sup-
port
Apps can respond to pressure-sensitive interactions from a Bluetooth sty- lus—for example, in a drawing app, pressing the stylus against the screen harder could result in a thicker line.
8. http://www.statista.com/statistics/266210/number-of-available-applications-in- the-google-play-store/.
http://play.google.com
Feature Description
Fig. 1.10 | Some Android Marshmallow features (http://developer.android.com/about/ versions/marshmallow/android-6.0-changes.html). (Part 2 of 2.)
ptg16518503
1.6
Packages
Android uses a collection of packages, which are named groups of related, predefined class- es. Some of the packages are Android specific, some are Java specific and some are Google specific. These packages allow you to conveniently access Android OS features and incor- porate them into your apps. The Android packages help you create apps that adhere to An- droid’s unique look-and-feel conventions and style guidelines,
Figure 1.12 lists many of the packages we discuss in this book. For a complete list of An- droid packages, see
Google Play category Some popular apps in the category
Books and Reference WolframAlpha, Dictionary.com, Audible for Android, Kindle Business Polaris Office, OfficeSuite 8, QuickBooks Online, PayPal Here Communication Snapchat, LinkedIn, Pinterest, Instagram, WeChat, Line Education Google Classroom, Star Tracker, Sight Words, Math Tricks Entertainment Showtime Anytime, History Channel, Discovery Channel Finance PayPal, Credit Karma, Google Wallet, Chase Mobile Games Pac-Man 256, Angry Birds 2, Fruit Ninja, Tetris, Solitaire Health & Fitness RunKeeper, ViewRanger GPS, Calorie Counter
Lifestyle Assistant, Horoscope, Food Network, Starbucks Live Wallpaper Facebook, Next Launcher 3D Shell, Weather Live
Media & Video VHS Camera Recorder, VivaVideo Pro, musical.ly, GIF Keyboard Medical Feed Baby Pro, CareZone, FollowMyHealth, Essential Anatomy Music & Audio SoundCloud, Spotify, Beats Music, Pandora, iHeartRadio News & Magazines BBC News, CBS News, NPR News, Reuters, NBC News Photography Google Camera, Instagram, Retrica, GoPro App, Pencil Sketch Productivity Pocket, Wunderlist, Microsoft Word, Google Docs, SwiftKey Shopping Zappos, Groupon, JackThreads, Fancy, Etsy, Home Depot Social Snapchat, Instagram, Meetup, textPlus, Pinterest, Tumblr Sports Fox Sports, theScore, NBA 2015–16, ESPN, CBS Sports Tools CM Security Antivirus, Clean Master, Google Translate Transportation Uber, Lyft, MarrineTraffic, BringGo, DigiHUD Speedometer Travel & Local Priceline, Google Earth, Eat24, GasBuddy, Hotels.com Weather AccuWeather, Weather Underground, Yahoo Weather Widgets Facebook, Pandora, Pocket Casts, Tasker, Weather Timeline
Fig. 1.11 | Some popular Android apps in Google Play.
http://developer.android.com/design/index.html
http://developer.android.com/reference/packages.html
ptg16518503
1.6 Packages 15
Several of the packages we use are from the Android Support libraries, which enable you to use newer Android features in apps that run on current and older platforms. For an overview of the key features in the Android Support libraries, visit:
https://developer.android.com/tools/support-library/features.html
Package Description
android.animation Classes for property animation. (Chapter 4’s Flag Quiz app and Chapter 5’s Doodlz app.)
android.app Includes high-level classes in the Android app model. (Chapter 4’s
Flag Quiz app and Chapter 5’s Doodlz app.)
android.content Access and publish data on a device. (Chapter 6’s Cannon Game app.)
android.content.res Classes for accessing app resources (e.g., media, colors, drawables, etc.), and device-configuration information affecting app behavior. (Chapter 4’s Flag Quiz app.)
android.database Handling data returned by the content provider. (Chapter 9’s Address Book app.)
android.database.sqlite SQLite database management for private databases. (Chapter 9’s
Address Book app.)
android.graphics Graphics tools used for drawing to the screen. (Chapter 4’s Flag Quiz
app and Chapter 5’s Doodlz app.)
android.graphics. drawable
Classes for display-only elements (e.g., gradients, etc.). (Chapter 4’s
Flag Quiz app.)
android.hardware Device hardware support. (Chapter 5’s Doodlz app.)
android.media Classes for handling audio and video media interfaces. (Chapter 6’s
Cannon Game app.)
android.net Network access classes. (Chapter 8’s Twitter® Searches app.)
android.os Operating-systems services. (Chapter 3’s Tip Calculator app.)
android.preference Working with an app’s user preferences. (Chapter 4’s Flag Quiz app.)
android.provider Access to Android content providers. (Chapter 5’s Doodlz app.)
android.support. design.widget
Android Design Support Library classes that enable recent GUI enhancements to run on current and older Android platforms. (Chapter 7’s Weather Viewer app.)
android.support.v4. print
Part of the v4 Android Support Library for use in platform API levels 4 and higher. Includes features for using the Android 4.4 printing framework. (Chapter 5’s Doodlz app.)
android.support.v7.app Part of the v7 Android Support Library for use in platform API levels 7 and higher. Includes application-compatibility library components, such as app bars (formerly action bars). (Chapter 7’s Weather Viewer
app.)
Fig. 1.12 | Android and Java packages used in this book, listed with the chapter in which they first appear. We discuss additional packages in Volume 2. (Part 1 of 2.)
ptg16518503
1.7
Android Software Development Kit (SDK)
The Android SDK provides the tools you’ll need to build Android apps. It gets installed with Android Studio. See the Before You Begin section (after the Preface) for details on downloading the software you’ll need to develop Android apps, including Java SE 7 and Android Studio.
Android Studio
Android Studio9 was announced at the Google I/O developer conference in 2013 and is now Google’s preferred Android IDE. The IDE includes:
• GUI designer
• code editor with support for syntax coloring and line numbering • auto-indenting and auto-complete (i.e., type hinting)
• debugger
• version control system • refactoring support and more.
The Android Emulator
The Android emulator, included in the Android SDK, allows you to run Android apps in a simulated environment within Windows, Mac OS X or Linux, without using an actual Android device. The emulator displays a realistic Android user-interface window. It’s par- ticularly useful if you do not have access to Android devices for testing. You should certain- ly test your apps on a variety of Android devices before uploading them to Google Play.
Before running an app in the emulator, you’ll need to create an Android Virtual Device (AVD), which defines the characteristics of the device on which you want to test, including the hardware, system image, screen size, data storage and more. If you want to
android.support.v7. widget
Part of the v7 Android Support Library for use in platform API levels 7 and higher. Includes GUI components and layouts. (Chapter 7’s
Weather Viewer app.)
android.text Rendering and tracking text changes. (Chapter 3’s Tip Calculator app.)
android.util Utility methods and XML utilities. (Chapter 4’s Flag Quiz app.)
android.widget User-interface classes for widgets. (Chapter 3’s Tip Calculator app.)
android.view User interface classes for layout and user interactions. (Chapter 4’s
Flag Quiz app.)
9. Android Studio is based on the JetBrains IntelliJ IDEA Java IDE (http://www.jetbrains.com/ idea/)
Package Description
Fig. 1.12 | Android and Java packages used in this book, listed with the chapter in which they first appear. We discuss additional packages in Volume 2. (Part 2 of 2.)
ptg16518503
1.7 Android Software Development Kit (SDK) 17
test your apps for multiple Android devices, you’ll need to create separate AVDs to emu- late each unique device, or use Google’s Cloud Test Lab
which enables you to test on many different devices.
You can reproduce on the emulator most of the Android gestures (Fig. 1.13) and con- trols (Fig. 1.14) using your computer’s keyboard and mouse. The gestures on the emulator are a bit limited, since your computer probably cannot simulate all the Android hardware features. For example, to test GPS apps in the emulator, you’ll need to create files that sim- ulate GPS readings. Also, although you can simulate orientation changes (to portrait or
landscape mode), simulating particular accelerometer readings (the accelerometer allows the device to respond to up/down, left/right and forward/backward acceleration) requires features that are not built into the emulator. The emulator can, however, use sensor data from an actual Android device connected to the computer, as described at
Figure 1.15 lists Android functionality that’s not available on the emulator. You can install your app on an Android device to test these features. You’ll start creating AVDs and using the emulator to develop Android apps in Chapter 2’s Welcome app.
https://developers.google.com/cloud-test-lab
http://tools.android.com/tips/hardware-emulation
Gesture Emulator action
Touch Click the mouse once. Introduced in Chapter 3’s Tip Calculator app. Double touch Double click the mouse.
Long press Click and hold the mouse. Introduced in Chapter 8’s Twitter® Searches app.
Drag Click, hold and drag the mouse. Introduced in Chapter 6’s Cannon Game app. Swipe Click and hold the mouse, move the pointer in the swipe direction and release
the mouse. Introduced in Chapter 7’s Weather Viewer app.
Pinch zoom Press and hold the Ctrl (Control) key. Two circles that simulate the two touches will appear. Move the circles to the start position, click and hold the mouse and drag the circles to the end position.
Fig. 1.13 | Android gestures on the emulator.
Control Emulator action
Back Esc
Call/dial button F3
Camera Ctrl-KEYPAD_5, Ctrl-F3
End call button F4
Home Home button
Menu (left softkey) F2 or Page Up button
Fig. 1.14 | Android hardware controls in the emulator (for additional controls, go to http://developer.android.com/tools/help/emulator.html). (Part 1 of 2.)
ptg16518503