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

Including resource files in your project


Android provides two options for including files in your project: the raw folder and the assets folder. Which option you use depends on your requirements. To start, we'll give a brief overview of each option to help you decide the best use:

  • Raw files
    • Included in the resource directory: /res/raw
    • As a resource, accessed through the raw identifier: R.raw.<resource>
    • A good place for storing media files such as MP3, MP4, and OGG files
  • Asset files
    • Creates a file compiled in your APK (does not provide a resource ID)
    • Access files using their filenames, generally making them easier to use with dynamically created names
    • Some APIs do not support a Resource Identifier and therefore require including as an Asset

Generally, raw files are easier to work with since they are accessed through the resource identifier. As we'll demonstrate in this recipe, the main difference is how you access the file. In this example, we will load both a raw text file and an asset text...