Book Image

Android 9 Development Cookbook - Third Edition

By : Rick Boyer
Book Image

Android 9 Development Cookbook - Third Edition

By: Rick Boyer

Overview of this book

The Android OS has the largest installation base of any operating system in the world. There has never been a better time to learn Android development to write your own applications, or to make your own contributions to the open source community! With this extensively updated cookbook, you'll find solutions for working with the user interfaces, multitouch gestures, location awareness, web services, and device features such as the phone, camera, and accelerometer. You also get useful steps on packaging your app for the Android Market. Each recipe provides a clear solution and sample code you can use in your project from the outset. Whether you are writing your first app or your hundredth, this is a book that you will come back to time and time again, with its many tips and tricks on the rich features of Android Pie.
Table of Contents (24 chapters)
Title Page
Copyright and Credits
Dedication
About Packt
Contributors
Preface
Index

Preface

Android was first released in 2007 after being acquired by Google, Inc. Initially, Android was primarily used on a handset. Android 3.0 added features to take advantage of the growing tablet market.

In 2014, Google announced Android had over 1 billion active users! With over 1 million applications available on Google Play, there's never been a more exciting time to join the Android community!

This year, 2018, marks a significant milestone for Android - 10 year anniversary since the first Android phone was released! And with that, we have a new OS version release as well - Android Pie. In this new edition of the book, we'll cover features released for the platform in several new topics across many chapters, as well as updates to existing popular topics to cover SDK changes. As usual, the Android platform is constantly changing!

Who this book is for

This book assumes basic familiarity with programming concepts and Android fundamentals. Or, if you are new to Android and learn best by jumping into the code, this book provides a wide range of the most common tasks. If you are new to Android, you can start at the beginning of the book and work your way through the topics as they build on previous knowledge.

As a cookbook, the topics are designed to be stand-along (with noted exceptions), to make it easy to jump to a particular topic and get the code working in your own application as quickly as possible.

What this book covers

Chapter 1, Activities, the Activity represents the fundamental building block for most applications. See examples of the most common tasks such as creating an activity, and passing control from one activity to another. 

Chapter 2, Layouts, while Activities are fundamental to the UI, the Layout actually defines what the user sees on the screen. Learn the main layout options available and best to use cases. 

Chapter 3, Views, Widgets and Styles, explores the basic UI object, from which all layouts are built. The chapter starts by exploring views and widgets - the basic building block of any app then goes on to styling the widgets and turning those styles into themes.

Chapter 4, Menus and Action Mode, teaches you how to use menus in Android. Learn how to create menus and how to control their behavior at runtime, including Action Mode.

Chapter 5, Fragments, shows how to create more flexible user interfaces by reusing UI components with Fragments.

Chapter 6, Home Screen Widgets, Search and the System UI, takes us to topics outside your app such as how to create a widget for the Home Screen, adding search functionality UI to your app and running your app in full-screen mode.

Chapter 7, Data Storage, compares multiple methods Android offers for persisting data, and when best to use each option.

Chapter 8, Alerts and Notifications, shows multiple options for displaying notifications to your users. Options range from alerts in your application, using the system notification and the “Heads Up notification”. 

Chapter 9, Using the Touchscreen and Sensors, learn the events for handling the standard user interactions, such as button clicks, long presses, and gestures. Access the device hardware sensors to determine orientation changes, device movement, and compass bearing.

Chapter 10, Graphics and Animation, bring your app to life with animations! Take advantage of the many options Android offers for creating animations – from simple bitmaps to custom property animations.

Chapter 11, A first look at OpenGL ES, when you need high-performance 2D and 3D graphics, turn to the Open Graphics Library. Android supports Open GL, a cross-platform Graphics API.

Chapter 12, Multimedia - Sounds and Camera, take advantage of the hardware features for playing audio. Use Android intents to call the default camera application or delve into the camera APIs to control the camera directly.

Chapter 13, Telephony, Networks, and the Web, use the Telephony functions to initiate a phone call and to listen for incoming phone events. See how to send and receive SMS (text) messages. Use the WebView in your application to display web pages and learn to use Volley to communicate directly with web services.

 

Chapter 14, Location and using Geofencing, shows you how to determine the user's location and the best-practices so your app doesn’t drain the battery. Use the new Location APIs to receive location updates and create Geofences.

Chapter 15, Getting your app ready for the Play Store, as your polish your app for the Play Store, learn how to implement more advanced features such as Alarms, AsynchTask for background processing and add Google Sign-In to your app.

Chapter 16, Getting started with Kotlin, offers a first-look at the new Android language and several topics to get you started.

To get the most out of this book

  1. You should know basic programming fundamentals. This book assumes the reader understands basic programming syntax and concepts. Language features such as if/then, for next and try/catch should already be familiar and understood. 
  2. Download and install the official Android development environment - Android Studio. Refer to the Hardware-Software List section for details.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Android-9-Development-Cookbook. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781788991216_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

<activity
    android:name=".MainActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There's more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.https://www.packtpub.com/