ebook img

2 Introduction to Mono for Android PDF

556 Pages·2012·21.95 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview 2 Introduction to Mono for Android

ffffiirrss..iinndddd iiii 22//2288//22001122 44::2277::4444 PPMM McClure ffi rs.indd V1 - 01/23/2012 PROFESSIONAL ™ ANDROID PROGRAMMING WITH MONO® FOR ANDROID AND .NET/C# FOREWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv CHAPTER 1 Introduction to Android, Mobile Devices, and the Marketplace . . . . . . . .1 CHAPTER 2 Introduction to Mono for Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 CHAPTER 3 Understanding Android/Mono for Android Applications . . . . . . . . . . . . 37 CHAPTER 4 Planning and Building Your Application’s User Interface . . . . . . . . . . . . 59 CHAPTER 5 Working with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 CHAPTER 6 Binding Data to Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 CHAPTER 7 Working with the File System and Application Preferences . . . . . . . . 183 CHAPTER 8 Programming with the Device Hardware . . . . . . . . . . . . . . . . . . . . . . . . .207 CHAPTER 9 Using Multimedia — Audio, Video, and the Camera . . . . . . . . . . . . . . .237 CHAPTER 10 Talking to Other Applications and Libraries . . . . . . . . . . . . . . . . . . . . . .269 CHAPTER 11 Developing Background Services and Asynchronous Code . . . . . . . .289 CHAPTER 12 Canvas and Drawables: Building Custom Android Graphics . . . . . . . .323 CHAPTER 13 Working with Location Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .371 CHAPTER 14 Internationalization and Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . .393 CHAPTER 15 Sharing Code Between Mono for Android, MonoTouch, and Windows Phone 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .417 CHAPTER 16 Preparing and Publishing Your Application to the Market . . . . . . . . . .445 CHAPTER 17 Android Tablets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .469 APPENDIX A Tips for Developers and the Future of Mono and Android . . . . . . . . . .495 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 ffffiirrss..iinndddd ii 22//2288//22001122 44::2277::4433 PPMM ffffiirrss..iinndddd iiii 22//2288//22001122 44::2277::4444 PPMM McClure ffi rs.indd V1 - 01/23/2012 PROFESSIONAL Android™ Programming with Mono® for Android and .NET/C# Wallace B. McClure Nathan Blevins John J. Croft IV Jonathan Dick Chris Hardy ffffiirrss..iinndddd iiiiii 22//2288//22001122 44::2277::4444 PPMM McClure ffi rs.indd V1 - 01/23/2012 Professional Android™ Programming with Mono® for Android and .NET/C# Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2012 by Wallace B. McClure, Nathan Blevins, John J. Croft IV, Jonathan Dick, Chris Hardy Published by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-02643-4 ISBN: 978-1-118-22215-7 (ebk) ISBN: 978-1-118-23581-2 (ebk) ISBN: 978-1-118-26075-3 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, elec- tronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through pay- ment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http:// www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accompanies a standard print version, you may request this media by visiting http://booksupport.wiley.com. For more information about Wiley products, visit us at www.wiley.com. Library of Congress Control Number: 2011930295 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other countries, and may not be used without written permission. Mono is a registered trademark of Novell, Inc. Android is a trademark of Google, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. ffffiirrss..iinndddd iivv 22//2288//22001122 44::2277::4455 PPMM McClure ffi rs.indd V1 - 01/23/2012 To my wife, Ronda, daughter, Kirsten, and son, Brad — Wallace B. McClure To my lovely wife and accomplice, Crystal; my beautiful daughter, Kitara; and my son, Tristan, whom we’ve just welcomed into this wondrous world. — Nathan Blevins To my wife, Valerie, and my sons, Jack and Conor — John J. Croft IV To my wonderful wife, Jennifer, for all of her support in everything I do, and her tolerance for my geeky and gadgetry obsessions! — Jonathan Dick To my wife, Cara for, once again, putting up with the long nights; to my parents, Hazel and Bob; and to my sister, Kate — Chris Hardy ffffiirrss..iinndddd vv 22//2288//22001122 44::2277::4455 PPMM McClure ffi rs.indd V1 - 01/23/2012 CREDITS EXECUTIVE EDITOR BUSINESS MANAGER Bob Elliott Amy Knies SENIOR PROJECT EDITOR PRODUCTION MANAGER Kevin Kent Tim Tate PROJECT EDITOR VICE PRESIDENT AND EXECUTIVE GROUP Victoria Swider PUBLISHER Richard Swadley TECHNICAL EDITORS Stephen Long VICE PRESIDENT AND EXECUTIVE PUBLISHER Jordan Cobb Neil Edde PRODUCTION EDITOR ASSOCIATE PUBLISHER Daniel Scribner Jim Minatel COPY EDITOR PROJECT COORDINATOR, COVER Gayle Johnson Katie Crocker EDITORIAL MANAGER PROOFREADER Mary Beth Wakefi eld Louise Watson, Word One New York FREELANCER EDITORIAL MANAGER INDEXER Rosemarie Graham Ron Strauss ASSOCIATE DIRECTOR OF MARKETING COVER DESIGNER David Mayhew Ryan Sneed MARKETING MANAGER COVER IMAGE Ashley Zurcher © Antonis Papantoniou / iStockPhoto ffffiirrss..iinndddd vvii 22//2288//22001122 44::2277::4455 PPMM McClure ffi rs.indd V1 - 01/23/2012 ABOUT THE AUTHORS WALLACE B. (WALLY) MCCLURE graduated from the Georgia Institute of Technology (Georgia Tech) in 1990 with a Bachelor of Science degree in electrical engineering. He continued his education there, receiving a Master’s degree in the same fi eld in 1991. Since that time, he has done consulting and development for such companies as the United States Department of Education, Coca-Cola, Bechtel National, Magnatron, and Lucent Technologies, among others. McClure has authored books on architec- ture, ADO.NET, SQL Server, AJAX, and Mobile Devices with Mono. He has authored two books on iPhone programming with MonoTouch and one book on Mono for Android. He specializes in mobile applications, application scalability, and application user interfaces. He is a Microsoft MVP, an ASPInsider, and a partner in Scalable Development, Inc. You can read Wally’s blog at www.morewally.com. Wally is married and has two children. When not writing software, he explores entrepreneurial efforts, plays golf, exercises, and hangs out with his family. NATHAN BLEVINS is a husband and father who has been working in application development for the past 10 years. Always intrigued by logical puzzles, mechanics, and problem solving, Nathan found his calling in software development and has been playing at work ever since. Living by the philosophy of “work to become, not to acquire,” Nathan has devoted himself to being a lifetime student, also working within the community as a speaker, educator, and overall technology enthusiast. In the past, Nathan has worked with various national and local businesses via his personal consulting company, Blevins Consulting. At present, Nathan is serving as a developer and business analyst for Bush Brothers & Company. Though his career began on the open source development stack in languages such as PHP and Python, Nathan’s main focus has been on ASP.NET and C# development since 2004. During the past few years, Nathan’s work has included mobile development platforms such as Android, Blackberry, and Windows Phone 7. Currently, Nathan is involved in the community as a member of the ASP.NET Insiders and as a public speaker. If you would like to get into contact with Nathan Blevins, please feel free to contact him through his personal blog at http://nathanblevins.com or via his Twitter account, @nathanblevins. JOHN J. CROFT IV graduated from the Georgia Institute of Technology in 1991, receiving a Bachelor’s degree in mechanical engineering. He then spent 5 years con- sulting for large companies, including Coca-Cola, BellSouth, and MCI. Work at these companies primarily involved C and C++ programming and object-oriented systems analysis. In 1995, Croft embarked on his entrepreneurial career by starting Computing Solutions. Computing Solutions is a technology fi rm that has provided quality service to over 200 clients nationwide. Computing Solutions clients have varied in both size and need, from Fortune 100s to small startup companies. Their problems have varied drastically as well, from large databases and executive information systems to lithotripter control and satellite telemetry. In 2003, ffffiirrss..iinndddd vviiii 22//2288//22001122 44::2277::4455 PPMM McClure ffi rs.indd V1 - 01/23/2012 viii x ABOUT THE AUTHORS Computing Solutions merged with McClure Development to become Scalable Development, Inc. SDI’s technology performances have included projects with Java, C#, and .NET applications. Recently, John has returned to the corporate world as a senior technical manager for Turner Broadcasting Systems. John has coauthored two other books on programming with .NET. He cur- rently lives in Atlanta with his wife, Valerie, and his two sons. JONATHAN DICK is a database administrator and software developer and has been working with .NET since its beta days. He now focuses on mobile application devel- opment, and has written several MonoTouch applications. He currently maintains open source .NET libraries for Apple iOS Push Notifi cations and Google Android Cloud to Device Messaging (APNS-Sharp and C2DM-Sharp), while contributing to other mobile-focused projects such as MonoTouch.Dialog and MonoDroid.Dialog. CHRIS HARDY, a Microsoft ASPInsider, is a .NET consultant focusing on MonoTouch and Mono for Android development working with Xamarin. Ever since MonoTouch was in beta, Chris has been developing and evangelizing MonoTouch and was one of the fi rst users to get a MonoTouch application onto the App Store. Speaking at conferences around the world on the subject, Chris has been a key part of the community and extended this by contributing to the Wrox book Professional iPhone Programming with MonoTouch and .NET/C#. You can follow him on Twitter @chrisntr. ABOUT THE TECHNICAL EDITORS STEPHEN LONG is a senior developer currently focusing on .NET and specializing in web and mobile development. He enjoys working with MVC frameworks, such as those provided with ASP.NET and the Android SDK, leveraging new and emerging technologies, and being a mentor to those around him. He is a self-described Google/Android fanboy, husband, and father of two wonderful daughters currently residing in Knoxville, Tennessee. Stephen graduated from the University of Memphis with a BSEE degree with a concentration in computer engineering. He can be found on twitter @long2know. JORDAN COBB has been fascinated by technology ever since receiving his fi rst computer, a 486 DX2, at the age of 12. His fi rst passion was network systems and hardware, but after becoming frus- trated in relying on third-party applications, or the lack thereof, to get the job done he delved into the world of software development. After dabbling in the PHP language for some time he moved to the .NET Framework and has been developing professionally for the past 9 years. Jordan enjoys interfacing software with physical devices, like Arduino, as well as other hobby electronics projects. When he is not at the keyboard, Jordan enjoys playing the occasional round of paintball, attend- ing conferences, and spending time with his new wife, Christine. The couple is expecting their fi rst child, Zoey, in April 2012. ffffiirrss..iinndddd vviiiiii 22//2288//22001122 44::2277::5577 PPMM

Description:
APPENDIX A Tips for Developers and the Future of Mono and Android 495 .. Getting Your Production/Release MD5 Fingerprint. 386. Creating .. build tool. A second compilation is typically performed when an application is executed. This . Android, as illustrated in Figure 1-2. How does
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.