Thursday, June 21, 2012

WP7 Platform Insights : Part 3 (Supported features)

In last two blogs I have discussed Windows Phone overview and app development related topics. Today we will discuss more about supported features in initial version of WP7. Also we will discuss about features which are added in mango and tango updates.
Basic features in 7.0
In this section, we will discuss major features supported by initial version of WP7 i.e. 7.0
  • Improved UI Design
    • WP7 supports slick, touch friendly UI similar Zune HD
    • Tiles serve as a shortcut to your favorite apps
    • Live tiles which can link to facebook profile or any other live information
  • Hubs
    • WP7 supports different social and productivity hubs
    • People hub aggregates your friends from your social networks
    • Picture hub gives access to all of your photos
    • Office hub will be useful for syncing documents between phone and PC
    • App Hub is lists of apps from Marketplace and also downloaded apps
  • Sensors
    • Accelerometer – It measures the three-dimensional force applied on a device.
    • Assisted GPS – Traditional GPS cannot provide accurate position when used in closed space. This error/drift can be avoided using AGPS (assisted GPS), which makes use position of Wi-Fi access points and cellular towers to provide more accurate position.
    • Proximity and Ambient light sensor – These sensors are available on WP7 devices. However, these are not available to developers through APIs.
  • Media
    • One of the best feature is developer can access FM Radio stations in their apps
    • You can integrate your app with Music + Videos hub
    • It supports PlayReady DRM
  • Data Storage/ Isolated Storage
    • WP7 supports sandbox model storage to improve security and reduce the unauthorized access and data corruption
    • WP7 supports three types of storage options like 
      • IsolatedStorageSettings class to store app settings (key/value pairs)
      • IsolatedStorageFile class to store files and folders
      • LINQ to SQL to store relational data
    • Isolated Storage Explorer (ISETool.exe) can be used for different I/O operations
  • Notifications
    • WP7 supports three types of notifications like tile, toast and raw
    • Tile notifications are used to update app tiles
    • Toast notifications will be added to status bar
    • Raw notifications can be delivered to running applications directly
Delicious features in Mango Update (7.5)
WP7 first version has been missing some of the most sought features available on other mobile platforms. Mango update (version 7.5) filled this gap by adding more than 500 features to WP7. Out of these 500 only few features stand out from others are like tethering, social feature and multitasking.
  • More social networks in people hub like Twitter, LinkedIn
  • Share Music and video content with Windows Live messenger
  • Bing experience is improved with Voice guidance for turn-by-turn navigation, Indoor Maps (US only) and Audio/Music search
  • TellMe (voice to text) service enables hands-free messaging and chatting
  • SkyDrive and Office-365 document syncing
  • IE9 mobile which supports hardware acceleration for HTML5 rendering
  • Wi-Fi hotspot support (carrier dependent)
  • Sensors
    • Gyroscope – measures rotational velocity on 3d axis
    • Compass – determines the angle by which device is rotated relative to earth’s magnetic north pole
    • Motion API combines data from compass, gyroscope and accelerometer sensors
  • Socket communication is supported
  • Alarms and Reminders
    • Both can be used as a scheduled notification
    • Sound file for alarm can be changed whereas reminders use default sound file
    • Clicking on alarm takes user to alarm app whereas clicking on reminders takes user to corresponding app which has set that reminder
  • Multitasking
    • Supports single foreground application
    • App can perform below actions in background
      • Playing audio
      • Scheduled tasks using background agents
      • HTTP file transfer requests
      • Scheduled notifications like Alarms and reminders
Features and limitations in Tango Update (7.5 Refresh)
This update has two branches. First branch does impose some restrictions on low-end (256MB RAM) devices while other branch adds some minor changes to high-end devices.
  • Missing features for 256MB RAM devices
    • Fast app switching
    • Generic Background agents
    • SkyDrive automatic photo upload
    • Managing podcast subscriptions and watching video podcasts
    • HD Video playback
  • New features
    • MMS supports multiple attachments, video and voice note
    • Location aware icon will be displayed whenever app accesses location
    • Supports exporting of contacts to SIM card
    • Memory status information
Update: Today Microsoft has announced major update to WP7 namely Windows Phone 8. To know more about WP8 features, visit this blog

Monday, June 18, 2012

WP7 Platform Insights : Part 2 (App Development)


Today we will explore WP7 application development frameworks and app development life cycle in detail.

Frameworks

Most of the developers working on Microsoft technologies are aware of two popular frameworks namely Silverlight and XNA. Silverlight is cross-platform, cross-browser implementation of .Net framework for building media experiences and rich interactive applications for the web on desktop. Microsoft uses XNA framework for game development on its most popular gaming platforms like Xbox 360, Zune HD and Windows 7.
Considering popularity of these frameworks and availability of expertise, Microsoft has decided to use these frameworks for its new mobile OS WP7. However, restrictions on mobile device like memory constraints and form factors forced Microsoft to tweak these frameworks slightly for WP7.
We listed imported features regarding these application frameworks below
  • Silverlight for Windows Phone
    • Based on Silverlight 4
    • Optimized runtime to display content on memory constrained devices
    • Hosted on client and will not support web apps
    • Additional features which are not part of Silverlight like
      • Gesture aware controls
      • Support for SIP (software input panel)
      • Manipulation events for touch input
    • Supports building and running managed applications
    • Useful for RIA style or XAML based UI and event driven app
    • Includes WP native controls, HTML browser control
  • XNA
    • Based on .Net framework 2.0
    • Single framework targeted for multiple gaming platforms
    • Greater portability using cross-platform input APIs which are orientation-aware and resolution-aware
    • Includes set of managed APIs for 2D/3D geometry, textures and shading
    • High performance gaming framework to create multi-screen 2D/3D games
    • Allows managing art assets (like models, meshes, textures)
Before mango update of WP7, developer has to use any one of the above frameworks for his application’s visual designs though sharing of some classes across framework was possible.
Mango update of WP7 removed this restriction and allowed to use combination of both frameworks for your application’s visual design as well. However, prefer using single framework based on your applications requirements. If at all required, combine these two frameworks in your application by using the new SharedGraphicsDeviceManager and UIElementRenderer class.

Development Lifecycle


Above diagram shows development lifecycle of WP7 apps.
Below are some of the highlights of this development lifecycle
  • Windows Live ID is necessary for publishing apps on marketplace
  • Your device need to be registered as test device for debugging purpose
  • If you unregister your test device, you can’t run manually installed (side loaded) apps
  • Maximum three devices can be registered per developer account
  • Zune software necessary to deploy app on device
In next blog we will explore features provided in WP7 initial version, mango and tango updates.

WP7 Platform Insights : Part 1 (Overview)


Today we will be discussing Microsoft’s latest mobile OS Windows Phone 7 (in short WP7). We can consider WP7 as a successor to Windows Mobile (WM) but not update to WM as WP7 developed from scratch. It is completely new refreshed mobile OS, which will compete with other mobile platforms. Focus of WP7 is more towards consumer as against Windows Mobile’s enterprise focus.

One of the major differentiator from other OS is its Metro design interface. Hub is another feature through which it combines local and online content. In addition, WP7 has tight integration with other Microsoft products like Xbox (most popular gaming platform), MS Office and Windows Live web-based services.


Brief History

In 2004, Microsoft started working on major update to WM under the codename ‘Photon’. However, this project came to end without any product release due to slowness. In 2008, Microsoft’s WM OS started losing its market share to Blackberry and iPhone. As an effect, Microsoft revamped the WM team in 2008 and started working on WM 7. Again, Microsoft failed to meet deadlines and it has released WM 6.5 as interim release instead of initially planned WM7.
Due to these hiccups, Microsoft developed new mobile OS from scratch in short span of time without providing backward compatibility. World saw the glimpse of Microsoft’s new mobile OS on 15 February, at Mobile World Congress (MWC) 2010 held in Barcelona. At MIX 2010 event, world witnessed some more details about this new OS. Finally, SDKs are arrived in September 2010.
Microsoft had many hiccups in OS naming also. Initially they released new mobile OS with name as ‘Windows Phone 7 Series’ transitioning from old windows mobile. As expected, this lengthy and difficult name came under criticism from around the world including developers and partners. Bowing to this pressure, Microsoft dropped ‘Series’ word from this name.
Year 2011, mobility world saw the new mega partnership between Microsoft and Nokia. As part of this partnership, WP7 became primary Smartphone OS for Nokia.


Platform Overview

Lets discuss how the WP7 application platform architecture is there and what development tools it provides.

Architecture

There are four main components in the WP7 Application Platform architecture


  • Runtimes
    • WP7 runtime supports Silverlight and XNA frameworks
    • You can run your Silverlight or XNA apps on WP7 with minor changes. These changes include adjusting UI for device’s screen resolution or making use of device specific features like GPS, Camera etc.
    • Runtime also includes phone specific components like sensors, Media etc.
  • Tools - When you install SDK, you will get many tools that are helpful for app development.
    • Visual studio – One of the best IDE is part of SDK. It supports debugger, designer, compiler, packager etc.
    • Expression Blend - Your UX team can use this tool and can create XAML files, which you can use it in your app directly. This helps developers and UX team to do their tasks independently.
    • Emulator – Developers can use emulator to run/debug their app before testing on actual device as it provides comparable performance to an actual device. WP7 emulator also supports emulating different device specific features like GPS, accelerometer etc. You can also take screenshots of your application.
    • XNA Game Studio – This is integrated game development environment used for Microsoft’s other platforms like Windows, Xbox 360 and Zune. Same tool is now available for WP7 developers. It includes other tools, which are useful for adding graphical and audio content into your game.
    • Documents – WP7 tools also includes sample codes, guides, API documentation etc.
  • Cloud Services – Cloud services are very useful to build powerful WP7 web applications with scalable features. It includes below mentioned services
    • Notifications (MPNS – Microsoft Push Notification Service) – Many applications need to fetch up to date information from server. For this, push notification is better as it reduces burden of polling and consumes less battery power.
    • Location – This cloud service is single source to get the position lookup data by making use of Wi-Fi, Cellular and GPS data. This service also includes AGPS, which improves fix for GPS.
    • Advertising SDK – This service is useful for monetizing your apps. Also provides efficient reporting mechanism.
    • Other services – Azure, Map, Identity, Social and Feeds are some other services which are supported WP7 platform.
  • Portal Services – Portal services supports marketplace related activities from single location. Below is list of some of the activities which portal services supports
    • Registration and validation – Developers can register here for App Hub using their Live ID.
    • Application submission – This includes set of online tools for helping developers to submit their apps in Marketplace. Here developers can track their apps certification status, provide updates to existing apps etc.
    • App Billing – Developers can use portal services to sell their paid apps. Marketplace supports mobile operator and credit card billing.
    • Business Intelligence – This is dashboard for your apps on marketplace. This dashboard shows all details of your apps like downloads, reviews, crashes etc.

Development Tools

We all know that Microsoft always provides best development tools compared any other technologies. Same is true in case of WP7. WP7 Developers can download and install Windows Phone SDK, which includes all necessary development tools and documents. WP7 SDK package contains below mentioned tools
Visual Studio 2010 Express for WP7
  • Development environment for WP7 which includes
    • Code editor and design surface for WP7
    • WP7 project templates
    • Toolbox containing WP7 controls
  • You can debug and deploy your apps on emulator or device
Note: If VS 2010 Professional or higher is already installed on your PC then WP7 SDK will install only plug-in for VS 2010 instead of VS 2010 Express for WP7
Silverlight SDK
  • Application framework used for writing RIA style user interfaces
  • It is XAML based and event driven app framework
  • Includes WP7 controls and web browser control
Expression Blend
  • Best UI design tool for designing XAML based interfaces for web and desktop applications
  • Accelerated results as design and development can be done independently
  • XAML files designed by UX team can be used by developer in their solutions directly
XNA Game Studio 4.0
  • Programming environment for creating games with VS
  • Includes XNA framework and managed libraries useful for game development for WP7, Windows, Xbox and Zune
WP7 Emulator
  • It can be used as a virtualized environment where you can debug, deploy and test your WP7 apps
  • Provides comparable performance to an actual device
  • Also supports simulation of GPS, accelerometer and orientation
  • Allows capturing screenshots
Other Tools
  • Advertising SDK allows you to monetize your apps
  • XAP deployment, isolated storage explorer and phone registration are some of the tools available as part of SDK
In next blog of this series, I will be discussing more about application development topics like frameworks and development lifecycle.

Thursday, February 16, 2012

Android C2DM: Part 3

In first two parts (Part 1 and Part 2) we have seen C2DM overview, architecture and workflow. Today in this part, we will explore more about error handling, comparison with other push technologies like Apple's APNS and Microsoft's MPNS etc. Finally, we will give references of some C2DM demo applications.
 
Error Handling
C2DM implementation should have error handling at different stages of C2DM workflow like while registration, sending registration ID to third party application server or sending push request to C2DM server. Mobile app and third party app server should handle HTTP error codes as usual. In this section, we will be discussing C2DM specific error handling only.

Registration Errors
Mobile app might get below mentioned errors as a response to registration intent.
  • SERVICE_NOT_AVAILABLE – App will get this error in two scenarios. First when a device gets internal server error (500) or Service unavailable (503) from server. When device is unable to read the response it received from server then also it gets this error. Application should retry for registration.
  • ACCOUNT_MISSING – As per pre-requisites, if there is no single logged in Google user present on device then we will get this error. App should convey this to user and open the settings account for adding new account.
  • AUTHENTICATION_FAILED – App gets this error when user gives wrong password for his Google ID.
  • TOO_MANY_REGISTRATIONS – When too many apps are C2DM registered from device, then C2DM server returns this error to avoid any abuse.
  • INVALID_SENDER – Sender Email ID is not white listed or not registered for C2dM. Therefore, C2DM server will not recognize sender ID and will return this error.
  • PHONE_REGISTRATION_ERROR – When user’s current device does not support C2DM then app will get this error.
Push Message Errors
When third party app sends HTTP post request to C2DM server for sending push message, it might get HTTP errors like 503 (service unavailable) or 401 (unauthorized), which it has to handle as usual. However, in this section we will discuss C2DM specific errors
  • QuotaExceeded – Too many messages from current sender ID
  • DeviceQuotaExceeded – Too many messages to device from sender ID
  • MissingRegistration – Request doesn’t contain mandatory registration_id field
  • InvalidRegistration – Request contains wrong registration_id
  • MismatchSenderId – Sender ID used for getting registration_id and sender ID contained in push request does not match.
  • NotRegistered – App got uninstalled or unregistered
  • MessageTooBig – Payload size more than allowed size (i.e. 1024 bytes)
  • MissingCollapseKey – Request doesn’t contain mandatory collapse key field
Comparison with other push technologies
In this section, let us see how Android C2DM is different from other push technologies available on other mobile platforms.


Platform
Parameters
Android

iOS
Blackberry
Windows Phone 7
Name
C2DM
APN
BPS
MPNS
Registration
(For push services)
Yes
No
Yes
No
OS Version
2.2+ (Froyo)
iOS 3.0 +
Mac X v7.0
4.2+
7.x
Payload Size
1 KB
256 bytes
8 KB
3 KB (+ 1 KB Header)
Payload Format
String
JSON
XML
XML
Expiry Time
No
Controllable
Controllable up to 30 days
No
Quota (per day)
200,000
NA
100,000
Unlimited
(500 for unauthenticated web services)
Queue/Channels support
Yes
(4 per app)
Yes
(1 per app)
Configurable
Channels
1 per app, 30 per device
SSL/TLS Support
Yes
Yes
Yes
Yes
Notification UI
App has to provide
In-Built
In-Built
Toast, Tile or Raw
Free/Paid
Free
Free
Free
Free
Delivery guarantee
No
No
No
No
Delivery status
No
No
Yes
No
C2DM –Cloud to Device Messaging
APNS – Apple Push Notification Service
BPS – Blackberry Push Service
MPNS – Microsoft Push Notification Service


Demo Applications
Developers can refer below mentioned three applications for C2DM implementation. First two demo applications are open source and give complete understandings of C2DM flow. Third application ‘Earthquake Alerter’ highlights best usage of C2DM and Google App Engine. 

JumpNote
This is notepad-like open source demo application/solution and it has support for bidirectional synchronization. Native mobile client app in this solution is makes use of C2DM while Google App Engine is used as a third-party application server. This also has web client built using Google Web Toolkit
For more details visit here 

Google Chrome to Phone
This is another open source C2DM solution, which includes chrome extension, Android app and third-party server (using Google App Engine). This solution allows user to send the links from Chrome browser to mobile device. 
For more details visit here 

Earthquake Alerter 
This application makes use of push notification to alert the user whenever there is earthquake that matches users predefined filtered criteria. User can create filter based on location, radius, magnitude etc. This solution uses C2DM and Google App Engine.
For more details visit here 

Update : Google has deprecated C2DM and replaced it with GCM. Please read more about GCM here.

Tuesday, January 31, 2012

Android C2DM: Part 2 (Lifecycle)

In Part 1 of this blog series we have seen C2DM overview. Today in this blog we will explore C2DM in details. We will see C2DM architecture and C2DM workflow.

C2DM Architecture
Below diagram explains high level C2DM architecture
Components
Three parties are involved in this C2DM architecture 
  • Mobile device running C2DM based Android app
  • Third Party app server will send push message to device through C2DM server
  • C2DM server receives messages from third party app server and sends to mobile device/app
Credentials
Different credentials passed between these parties while transferring C2DM message to authenticate involved parties and make secured data transfer between them. These credentials explained below
  • Sender ID/Email used in C2DM signup process and is associated with application’s developer
  • Application ID (package name) ensures messages are delivered to correct application
  • Registration ID issued by C2DM server is uniquely represents app running on specific device
  • Google User Account for at least one logged in user on device
  • Auth token required to get authorized access to Google services like C2DM

C2DM Workflow
Above diagram shows C2DM workflow in detail starting from C2DM registration to actual message delivery. These workflow steps grouped into three processes/categories as given below
  • C2DM setup
  • Sending message
  • Receiving message
Below sections gives more details about these three processes
C2DM Setup
  • C2DM signup - App developer has to sign up for C2DM service before implementing C2DM in his app. In signup process, he has to provide his app ID (package name) and Role Account Email ID. Generally, white listing of your account and getting developer quota is very quick. This is one time process for each application.
  • C2DM registration - Android app registers itself for C2DM service by firing registration intent (com.google.android.c2dm.intent.REGISTER). App includes additional parameters in this intent like sender (Email ID used in C2DM signup process) and app (package name).
  • Get Registration ID - Android app has to register broadcast receiver for registration intent (com.google.android.c2dm.intent.REGISTRATION). Google will send this intent upon successful registration.
  • Send registration ID to third Party App Server - Application has to send registration ID received from C2DM server to third party App server. We recommend sending device ID along with registration ID so that third party app server can update it into its database against device.
  • Storing registration ID - Third party app server stores or updates registration ID received from Android app in a database. App server uses this ID for sending message to Android apps.
  • Unregistering C2DM - When Android app does not want to receive C2DM message any more then it can do by calling unregister intent. In response C2DM server will send response which app can use to notify user about un-registration.
Sending message
  • Get Authentication Token - App server can get the authentication token by providing sender ID (Email ID) and password to Google’s client login service. You can get this token via any http tools or command line tools like curl. However, we recommend you to get the authentication token programmatically because over a time this might be changed.
  • App server initiates message sending - App server makes post request to Google’s C2DM server. This request includes auth token and registration ID. This request also contains payload data (key-value pairs) and collapse key (used to collapse group of like messages when device is offline). If C2DM server receives optional parameter delay_while_idle from app server in above request, it will not send message immediately if device is in idle.
  • C2DM server validates credentials - C2DM server will validate credentials received from app server by sending those details to Google authentication service.
  • Queue the message - Once credentials validated C2DM server queues the message.
  • Initiate message delivery - C2DM server initiates message delivery by sending request to C2DM messaging server.
  • Message Delivery - If targeted device (decided based on registration ID) is online then C2DM messaging server delivers message to it. After successful delivery, messaging server removes it from message queue.
Receiving message
  • Receive message - Android device running registered app receives message from C2DM server. Android system extracts key/value pairs from message payload. It then broadcasts the receive intent (com.google.android.c2dm.intent.RECEIVE) with extra parameters.
  • Process message - Application’s broadcast receiver receives intent along with additional information like account name and message. Application processes this data for further usage.
In Part 3 of this blog series we will see error handling, comparison with other push technologies and list of demo applications.

Update : Google has deprecated C2DM and replaced it with GCM. Please read more about GCM here.

Tuesday, January 17, 2012

Android C2DM: Part 1 (Overview)

Today we will be exploring Google’s own cloud based push technology called C2DM (Cloud to Device Messaging) available for Android platform. C2DM helps third party Android app developers to receive push notifications sent by their application server.
Before getting into C2DM details let’s see why push is required.

Why Push is required?

Most mobile solutions have client-server architecture where mobile apps frequently need to download updated data from server. In some situations server need to push some short messages to mobile client like notification regarding new app update or event. For these kinds of features, we can use polling or push mechanism.
In polling mechanism, mobile app pings server periodically and checks if any new data is available for download. Polling is easy to implement and works well in most of the situations but tricky part is selecting the frequency for polling. Polling rarely can make data on device stale and polling frequently can create stress on server and network. This approach is not suitable for mobile devices as it uses precious network bandwidth more and so battery consumption will be more.
Other alternative is push mechanism for which we can follow two different implementation approaches. First approach is using proper push bearer, a network mechanism that can deliver unsolicited messages to devices. SMS and Blackberry’s proprietary push solution are the examples of push bearer. Second implementation approach is to simulate this technology by opening TCP connection to the push server. As we know TCP streams are full duplex (having pair of byte streams, one following each direction), server can push data to device anytime provided stream is active.
Most Smartphone platforms like iOS, Blackberry, Windows Mobile have their own push technology. Android OS was exception till its Froyo release as Android’s framework does not has support for push technology and app developers have to use open source alternatives like MQTT, Urban Airship and Deacon. With Froyo release, Android received support for Google’s own cloud based push technology known as C2DM.

C2DM Overview
C2DM is a solution to send real time notifications to user on his Android handset and most Google Services (Gmail, Market, Maps etc.) supports it. C2DM server/service takes care of all aspects of queuing and delivery of messages to target devices running developer’s target apps. C2DM also acts as an intermediary between developer’s App server and Android device.
Before moving into implementation details, we will see prerequisites for C2DM implementations, advantages and limitations of C2DM service and some guidelines for C2DM implementation.

Prerequisites

  • Android 2.2+ Device or Emulator
  • At least one logged in Google user on device/emulator
  • Application server which can talk HTTP and connect to C2DM server
  • Android application should have permissions to receive C2DM message and to make internet connection
  • Developer must register on C2DM site to use C2DM for his application and to get developer quota for C2DM messages.

Advantages

  • Application need not be running in background to receive push messages as those gets delivered to your app (Intent Receiver) by system using Intent broadcast.
  • It does not create additional burden on network as it uses existing connection to Google services.
  • Data delivery to device will always secured as device to C2DM server connection supports SSL.
  • Broken connections will be re-established using heartbeat implementation.
  • C2DM framework does not provide any built-in user interface to display the received push message content. C2DM framework provides full freedom to application so that it will have full control over the received raw message content. For example, the application might post a notification, display a custom user interface, or silently synchronize data.

Limitations

  • Push message size limit is 1K (1024 bytes)
  • C2DM framework doesn’t give guarantee about delivery or order of push messages
  • C2DM sender account will have daily limit on total number of messages sent as well as messages sent per device. Currently total limit is 200,000 messages per day.

Guidelines

  • When Google service is down your application will get HTTP error code 503 along with retry value. Your app should respect these kinds of errors and it should have advanced error-handling mechanism in place.
  • Your solution should have its own queue mechanism in place, which will be useful when Google C2DM service returns over quota error.
  • Application server should not send large data; instead, it has to send ‘tickles’ to your application telling it to download latest data from server.
  • Avoid using ‘Role Account Email ID’ on device
Part 2 of this blog will cover C2DM architecture and life-cycle in details.

Update : Google has deprecated C2DM and replaced it with GCM. Please read more about GCM here.