Book Image

Xamarin Mobile Development for Android Cookbook

By : Matthew Leibowitz
Book Image

Xamarin Mobile Development for Android Cookbook

By: Matthew Leibowitz

Overview of this book

Xamarin is used by developers to write native iOS, Android, and Windows apps with native user interfaces and share code across multiple platforms not just on mobile devices, but on Windows, Mac OS X, and Linux. Developing apps with Xamarin.Android allows you to use and re-use your code and your skills on different platforms, making you more productive in any development. Although it’s not a write-once-run-anywhere framework, Xamarin provides native platform integration and optimizations. There is no middleware; Xamarin.Android talks directly to the system, taking your C# and F# code directly to the low levels. This book will provide you with the necessary knowledge and skills to be part of the mobile development era using C#. Covering a wide range of recipes such as creating a simple application and using device features effectively, it will be your companion to the complete application development cycle. Starting with installing the necessary tools, you will be guided on everything you need to develop an application ready to be deployed. You will learn the best practices for interacting with the device hardware, such as GPS, NFC, and Bluetooth. Furthermore, you will be able to manage multimedia resources such as photos and videos captured with the device camera, and so much more! By the end of this book, you will be able to create Android apps as a result of learning and implementing pro-level practices, techniques, and solutions. This book will ascertain a seamless and successful app building experience.
Table of Contents (20 chapters)
Xamarin Mobile Development for Android Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

With a rapid increase in the use of mobile devices everywhere, developing for Android takes advantage of this trend to reach the widest market available to any mobile platform. Along with creating awesome Android apps, Xamarin allows the use of the mature .NET Framework. .NET is a massive framework that is supported on almost all platforms, including iOS, Windows, Mac OS X, and Linux.

Developing apps with Xamarin.Android allows you to use and reuse your code and skills on different platforms, making you more productive in any sort of development. Although not a write-once-run-anywhere framework, Xamarin provides native platform integration and optimizations. There is no middleware; Xamarin.Android talks directly to the system, taking your C# and F# code directly to the low levels.

What this book covers

Chapter 1, Working with Xamarin.Android, allows us to create native Android apps with the strengths of C# and .NET. Using C#, we can develop native Android apps and at the same time have the ability to share code with other platforms.

Chapter 2, Showing Views and Handling Fragments, explores one of the most important parts of Android apps—the user interface, as it is the most visible part of an app. When creating apps for Android, there are numerous different ways available to create these interfaces.

Chapter 3, Managing App Data, consists of the program that almost all apps make use of to process data. Android provides many ways to manage data, each being different and useful for different purposes. Data can be stored in a file, a dictionary, or in a SQLite database.

Chapter 4, Presenting App Data, is only useful to a user if the user is able to view it. Android has several means to present data, the most common being some form of list or collection.

Chapter 5, Communicating with the Outside World, explains communication, which is possibly the most important part of interaction, both between humans and technology. Most Android devices are built with Cellular, Wi-Fi, Bluetooth, or NFC communication technologies.

Chapter 6, Using Background Tasks, is where the users expect mobile apps to be fluid, dynamic, and most of all, responsive. Long-running tasks, even those running for a few milliseconds, must be run in the background to keep an app responsive.

Chapter 7, Notifying Users, explains notifications, which draw the user's attention to let him/her know something has happened. Android apps can present notifications in several ways, ranging from a quick popup to a persistent message from a remote server.

Chapter 8, Interacting with Other Apps, explains that users have many apps installed on their Android devices. By developing apps to be aware of other apps, our apps can communicate and request data from these other apps.

Chapter 9, Presenting Multimedia, consists of an explanation of audio, video and photos, the most vivid means to convey information to the user. By making use of Android's many features, an app can present a user with dynamic images and sounds. This can be used to provide a function or enhance other functionality.

Chapter 10, Responding to the User, explicates that a user can interact with Android apps in many ways. The user can manipulate virtual objects using the device's touch screen, or trigger the sensors by moving the device in the physical world.

Chapter 11, Connecting to Wearables, is one of the newest things with regard to technology; it is the increase in wearable devices. Android Wear is a special version of Android that allows device manufacturers to create wearables and permit typical Android apps to run on them.

Chapter 12, Adding In-App Billing, elucidates Android app developers can capitalize on the fact that users are willing to pay for new or additional features in the app. This is especially the case with mobile games that support purchasing virtual products or subscriptions.

Chapter 13, Publishing Apps, posits that once an Android app has been created, the next step is to release it into the world. Google has created the Google Play store, which can be used to distribute mobile and wearable apps. Before distribution, mobile apps can be compressed and protected against malicious users.

What you need for this book

This book will provide you with the necessary knowledge and skills to be part of the mobile development era using C#. Covering a wide range of recipes such as creating a simple application and using device features effectively, it will be your companion during the complete application development cycle.

Starting from installing the necessary tools, you will be guided step-by-step on everything you need to develop an application, ready to be deployed. You will learn best practices for interacting with the device's hardware, such as the GPS, NFC, and Bluetooth. Furthermore, you will be able to manage multimedia resources, such as photos and videos captured with the device's camera, and much more!

Who this book is for

If you are a C#/.NET developer with no previous experience in Android development, or you are a Java developer who wants to create complete Android applications in C# and deploy them to the Play Store, then this book is ideal for you. Having no experience with Xamarin will not hamper your interests.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

[Activity(
  Label = "My App",
  MainLauncher = true,
  Icon = "@drawable/icon")]
public class MainActivity : Activity
{
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="buttonText">Hello World!</string>
</resources>

Any command-line input or output is written as follows:

adb shell bmgr backup <android-package-name>
adb shell bmgr run
adb shell bmgr restore <android-package-name>

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the Download Xamarin for Windows or Download Xamarin for OS X links, depending on the operating system you are using."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.