Writing Windows Mobile Application Using Google Data Apis

Google+ Pinterest LinkedIn Tumblr +


Google Data APIs are a set of verstatile interfaces to access and manage your data related to Google services. Developers can easily integrate and extend their applications using Google Data APIs since they are based on standard protocols like XML and HTTP. There are client libraries available for popular languages and development platforms. The .NET client library ships with assemblies that also target the .NET compact framework.

Microsoft Windows Mobile platform supports .NET compact framework and is based on Windows Embedded CE. In this article, we will look at the steps involved in developing and deploying a simple application for Windows Mobile that helps administrators manage thier Google Apps Domain.

Environment Setup

I will be using Microsoft Visual Studio 2008 on Windows Vista to demonstrate the setup. However, the same steps can be followed for Visual Studio 2005 and/or Windows XP.

  • Setting up Device Emulator The latest version of Microsoft Device Emulator is Version 3.0 which should be installed along with VS2008. By default, the installation directory is C:\Program Files\Microsoft Device Emulator. If you do not have Microsoft Device Emulator installed.

  • Setting up Windows Mobile Center – To sync your emulator with the host OS, you need to run Windows Mobile Center. For Windows versions prior to Vista, this program is called ActiveSync

  • Windows Mobile 6.0 SDKs – Though you can develop with Windows Mobile 5.0 installed with Visual 2008, we will be developing the sample application using Windows Mobile 6.0 SDK which also comes with additional skins for the emulator. You can choose to develop with Windows Mobile 5.0 SDK as there are no deviations in the development as far as the sample application is concerned.

  • Google Data APIs – Download and install the latest version of .NET client library. There is a MSI installer for the library and following the default settings should be good enough.

Once all the above components are installed, the next step involves configuring the Device Emulator and Windows Mobile Center to sync with each other. Open the Mobile Device Settings and check ‘Allow connections to one of the following’ and choose DMA from the combobox. Windows XP users can follow the same steps in ActiveSync.

Windows Mobile Center

Now, start the Device Emulator Manager from C:\Program Files\Microsoft Device Emulator\1.0\dvcemumanager.exe and right-click Windows Mobile 6.0 Classic Emulator and choose connect . This will bring up the emulator in a new window. With Windows Mobile Device Center running , right click the emulator again in the device manager and select cradle. When cradled, the emulator synchronizes with Windows Mobile Device center which autodetects the emulator. Choose ‘Connect without setting up the device’ option from Windows Mobile Device Center. You should now be able to open Internet Explorer in the emulator and browse the Internet.

Windows Mobile Center

Writing Code

Creating a new Project

Open Visual Studio 2008 and create a new ‘Smart Device’ project from the project templates. Choose the ‘Target Platform’ as ‘Windows Mobile 6 Professional SDK’ in the next screen and application type as ‘Device Application’. To build an Application on top of Google Data APIs, we need to add references of the assemblies installed earlier to this project. The mobile assemblies are available here:
C:\Program Files\Google\Google Data API SDK\Redist\Mobile\WindowsMobile

Windows Mobile Center

The project template will create a Winform customized to the size of the target device. Drop a couple of textboxes from the toolbox to the form for accepting admin auth credentials and add a menu item for signing in. The event handler for the menu item click will make the necessary API calls using Google Apps API and authenticate the admin.

try{String domainName = txtEmail.Text.Split(newchar[]{'@'})[1];// Initialize AppsServive & Retrieve Admin Details        service =newAppsService(domainName, txtEmail.Text, txtPasswd.Text);UserEntry entry = service.RetrieveUser(txtEmail.Text.Split(newchar[]{'@'})[0]);        statusBar1.Text="Hello "+ entry.Login.UserName;        mItemLogin.Enabled=false;  mItemLogin.Enabled=false;}catch(AppsException e){        statusBar1.Text= e.Message;}

You can create further UI for managing users and associate menu items with them. For example, to create new users, place the following code in the click event handler:

privatevoid btnCreateUser_Click(object sender,EventArgs e){try{UserEntry entry = service.CreateUser(newUserName.Text.Trim(), firstname.Text.Trim(), familyname.Text.Trim(), password.Text.Trim());        statusBar1.Text= entry.Login.UserName+" created successfully";}catch(AppsException exception){        statusBar1.Text= exception.Reason;}}

The final step in the development of this sample is to setup our certificate policy since all API calls are over HTTPS. The actual handset will have certificate store setup but for the emulator we can either setup a store or define a custom certificate policy. This can be done by providing an implementation of System.Net.ICertificatePolicy. For testing purpose, we will trust all certificates for now.

publicclassTrustAllCertificatePolicy:System.Net.ICertificatePolicy{publicTrustAllCertificatePolicy(){}publicboolCheckValidationResult(System.Net.ServicePoint sp,        X509Certificate cert,WebRequest req,int problem){returntrue;}}

And during application startup, we need to register our policy:


Note: The underlying OS environment and device information can be obtained by issuing native calls to the system. You should implement a more secure policy when deploying to real hardware.


Windows Mobile Center

Deployment of mobile applications for testing and debugging is very simple and straightforward.

  • Make sure you have Device Emulator and Windows Mobile Device Center running in Cradle mode.

  • Once you have compiled your solution in Visual Studio, press F5 (Debug). This will launch a dialog box asking you to choose an emulator.

  • Select Windows Mobile 6.0 Classic Emulator and press Deploy. Your program will now be packaged and deployed to the already running emulator.

  • Add breakpoints in your code to debug the API calls.



You now have an environment ready to develop Google Data API powered applications on Windows Mobile platform.


About Author

Leave A Reply