www.it-ebooks.info ffirs.indd iiffirs.indd ii 7/13/11 7:20:43 AM7/13/11 7:20:43 AM www.it-ebooks.info WINDOWS ® PHONE 7 PROGRAMMING FOR ANDROID™ AND iOS DEVELOPERS FOREWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii CHAPTER 1 What’s New in Windows Phone 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 CHAPTER 2 The Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 CHAPTER 3 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 CHAPTER 4 User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 CHAPTER 5 Application Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 CHAPTER 6 Web Services and Push Notifi cations . . . . . . . . . . . . . . . . . . . . . . . . . . . .113 CHAPTER 7 Leveraging Location and Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 CHAPTER 8 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 CHAPTER 9 Multimedia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .205 CHAPTER 10 Utilizing System Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .235 CHAPTER 11 What You Need to Do about Security . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 APPENDIX A An Introduction to Smartphone Chipset . . . . . . . . . . . . . . . . . . . . . . . . . 277 APPENDIX B An Introduction to Microsoft Expression Blend for Windows Phone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 APPENDIX C Sample Applications Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 ffirs.indd iffirs.indd i 7/13/11 7:20:43 AM7/13/11 7:20:43 AM www.it-ebooks.info ffirs.indd iiffirs.indd ii 7/13/11 7:20:43 AM7/13/11 7:20:43 AM www.it-ebooks.info Praise for Windows Phone 7 Programming for Android and iOS Developers “Among quite a few Windows Phone 7 programming books on the market, this book is one of the best for iOS and Android developers who look into creating applications on the new Windows Phone 7 platform. It is also an excellent desktop reference for mobile computing courses in schools, as it provides architectural overview of many popular mobile technologies on the three major mobile platforms, as well as sample code that will help students understand the technologies and develop programming skills for Windows Phone quickly. —Dr. Lionel M. Ni Chair Professor and Dean of HKUST Fok Ying Tung Graduate School Hong Kong University of Science and Technology “Mobile is a rapidly growing space that is yet to reach its full potential and reach worldwide. The combination of mobility, form factor, price, social media, and a global market is enabling scenarios that previously were either hard to imagine or to develop. Developers, both professional and otherwise, are fl ocking to mobile platforms to create applications and games. An approachable, effective, integrated application platform is a goal that every software vendor should be aiming for. The Windows Phone 7 application platform enables developers to create engaging consumer experiences running on a Windows Phone. It is built upon existing Microsoft tools and technologies such as Visual Studio, Expression Blend, Silverlight, and the XNA framework. Developers already familiar with those technologies will be able to create new applications for the Windows Phone quickly and easily. “This book helps you to understand the Windows Phone application framework. It focuses on Windows Phone design guidelines, provides guidance architecture, and solidifi es it with hands-on, real-world development scenarios. It is comprehensive, highly readable, and replete with useful real-world examples. I highly recommend this book for smartphone developers, IT professionals, and engineering managers. Whether you are new, or one who has experience on the iOS and Android platforms, this book serves as the ideal reference for development on the Windows Phone.” —Saty Bahadur Principal Development Manager Windows Phone Engineering Microsoft Corporation ffirs.indd iiiffirs.indd iii 7/13/11 7:20:43 AM7/13/11 7:20:43 AM www.it-ebooks.info “With Microsoft back in the game with Windows Phone, and with a growing number of Windows Phone applications in end-user hands, more and more smartphone developers are looking for books to learn how development on Windows Phone works. “This book provides much-needed architecture guidance, theory, and hands-on practice for real-world cases aimed at developers. It is comprehensive, highly readable, and replete with useful examples. This book is exceedingly useful for mobile developers, mobile users, IT engineers, and managers.” —Quincy Milton Principal Test Manager Windows Phone Customer Experience Engineering Microsoft Corporation “This timely book will be invaluable to the many individuals and organizations that wish to extend existing development skills in iOS and/or Android onto the Windows Phone 7 platform. The book’s brilliant approach of focusing on the differences between Windows Phone 7 and the mobile platforms the reader already knows makes for remarkably quick and effi cient learning.” —Ib Green Head of Capacity Teleca USA, Inc. ffirs.indd ivffirs.indd iv 7/13/11 7:20:44 AM7/13/11 7:20:44 AM www.it-ebooks.info Windows ® Phone 7 Programming for Android™ and iOS Developers ffirs.indd vffirs.indd v 7/13/11 7:20:44 AM7/13/11 7:20:44 AM www.it-ebooks.info ffirs.indd viffirs.indd vi 7/13/11 7:20:44 AM7/13/11 7:20:44 AM www.it-ebooks.info Windows ® Phone 7 Programming for Android™ and iOS Developers Zhinan Zhou Robert Zhu Pei Zheng Baijian Yang John Wiley & Sons, Inc. ffirs.indd viiffirs.indd vii 7/13/11 7:20:44 AM7/13/11 7:20:44 AM www.it-ebooks.info Windows® Phone 7 Programming for Android™ and iOS Developers Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2011 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-02197-2 ISBN: 978-1-118-15420-5 (ebk) ISBN: 978-1-118-15422-9 (ebk) ISBN: 978-1-118-15421-2 (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, electronic, 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 payment 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. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2011931747 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. Windows is a registered trademark of Microsoft Corporation. Android is a trademark of Google, Inc. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book. ffirs.indd viiiffirs.indd viii 7/13/11 7:20:45 AM7/13/11 7:20:45 AM www.it-ebooks.info [...]... applications for iOS devices and Google Android devices Mobile applications for Windows Phone 7 (WP7) are poised to grow in the next several years, driven by the software giant’s mobile strategy and collaborations with handset partners such as Nokia, HTC, and Samsung In order for many of the iOS and Android developers to port their applications to WP7 or to create new applications, it’s important to understand... Application Execution Model and Life Cycles Application Execution Model and Life Cycles in Windows Phone 7 Comparing Application Model and Life Cycles in Android and iOS Preserve/Restore Application and Page Transient States for Windows Phone 7 Using Launchers and Choosers Work-Around Solutions in Windows Phone 7 Multitasking Background Service Data Sharing System Event Hooks 43 44 47 50 59 60 60 61 61 61... with Android and iPhone Operating System Application Framework Application Store Process 1 2 2 3 4 6 7 7 8 8 10 12 Summary 13 CHAPTER 2: THE DEVELOPMENT ENVIRONMENT Overview Using Windows Phone 7 Developer Tools 15 15 17 Creating WP7 Applications with Visual Studio Testing WP7 Applications in the Windows Phone Emulator Testing WP7 Applications on the Actual Windows Phone Device 17 21 26 Publishing Windows. .. managed application approach and the emergence of the Silverlight and XNA If you are entirely new to a Windows Phone, you’ll fi nd this book is written to provide you a conceptual map and bridge you over to Windows Phone 7 It’s full of comparisons and mappings (e.g., UI controls, compliance rules, etc.) from Android and iOS to Windows Phone 7 It also highlights the UI, platform, and service innovations This... Microphone Accessing the Microphone on iOS Accessing the Microphone on Android Accessing the Microphone on WP7 Accessing the Camera 235 235 236 2 37 238 239 239 240 242 Accessing the Camera on iOS Accessing the Camera on Android Accessing the Camera on WP7 Using Sensors 242 243 244 245 Accessing the Sensors on iOS Accessing the Sensors on Android Accessing Sensors on WP7 246 246 248 Utilizing FM Radio and. .. P2P and Wrox books To read the FAQs, click the FAQ link on any P2P page xxxii www.it-ebooks.info flast.indd xxxii 7/ 13/11 7: 23:25 AM 1 What’s New in Windows Phone 7 WHAT’S IN THIS CHAPTER ➤ An architectural overview of WP7 ➤ Comparisons with iOS and Android Mobile application developers will fi nd it useful to have an architectural understanding of the underlying Windows Phone 7 (WP7) software platform... Publishing Windows Phone 7 Applications to the Marketplace 28 Preparation Submission Post-Submission Actions Comparisons with Android and iPhone Summary 28 30 35 35 36 CHAPTER 3: FUNDAMENTALS 39 Basic Application Project Structure Application Project Structure for Windows Phone 7 Comparing Application Project Structure for Android and iOS 40 40 42 www.it-ebooks.info ftoc.indd xix 7/ 13/11 7: 24:11 AM CONTENTS... WP7VideoPlayerDemo WP7EnrichedMoviePlayerDemo Chapter 10 301 301 302 302 303 WindowsPhoneMic WPCamera WP7FMRadio MediaPicker 303 303 303 304 Chapter 11 304 AES Hash BlendWP7App1 304 305 305 INDEX 3 07 xxiv www.it-ebooks.info ftoc.indd xxiv 7/ 13/11 7: 24:13 AM FOREWORD In 2010, Microsoft launched Windows Phone 7 globally Windows Phone 7 came to market with a new application programming model and a suite of... new WP7 operating system, and to become familiar with various application development patterns from an iOS -Android- WP7 comparison standpoint This book aims at addressing this need by providing essential information, technical analysis, and working samples to help iOS and Android developers create applications on WP7 WHOM THIS BOOK IS FOR The book targets mainly experienced mobile application developers. .. help developers write applications and then control the pricing, sales, and improvement of their applications I was the Director of Test for Windows Phone 7 Services leading up to and including the launch of Windows Phone 7 Our focus on the developer as a critical part of the Windows Phone 7 ecosystem has produced a growing commercial opportunity for software developers It’s also created a growing and . for Windows Phone 7 Programming for Android and iOS Developers “Among quite a few Windows Phone 7 programming books on the market, this book is one of the best for iOS and Android developers who. Phone 7 Programming for Android and iOS Developers ffirs.indd vffirs.indd v 7/ 13/11 7: 20:44 AM7/13/11 7: 20:44 AM www.it-ebooks.info ffirs.indd viffirs.indd vi 7/ 13/11 7: 20:44 AM7/13/11 7: 20:44. www.it-ebooks.info ffirs.indd iiffirs.indd ii 7/ 13/11 7: 20:43 AM7/13/11 7: 20:43 AM www.it-ebooks.info WINDOWS ® PHONE 7 PROGRAMMING FOR ANDROID AND iOS DEVELOPERS FOREWORD . . . . . . . . . . . . . .