Over a million developers have joined DZone.

Cordova (Formerly PhoneGap) - Getting Started in Windows Phone

· Mobile Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

In this article I will talk about how to get started with Cordova (formerly PhoneGap) in Windows Phone.

Step 1: Download PhoneGap from here. At the time of writing this article lates version of PhoneGap available was 2.0.0.

Step 2: Unzip the downloaded file.

Step 3: Search for CordovaStarter-2.0.0.zip in the unzipped folder downloaded in the above step. In earlier version it was PhoneGapStarter.zip. In 2.0.0 the location of CordovaStarter-2.0.0.zip is as shown below.

phonegap cordova starter

Step 4: Place the CordovaStarter-2.0.0.zipĀ in \My Documents\Visual Studio 2010\Templates \ProjectTemplates

phonegap cordova VS2010 project templates

Step 5: Now open VS2010 and Create New Project, Select Visual C# from Installed Templates option and you will get option of CordovaStarter-2.0.0. Now click OK.

Phonegap cordova new project

Step 6: The project structure looks like below in Cordova 2.0.0.

phonegap cordova solution

Step 7: Now we are all set to use PhoneGap or Cordova. Open index.html. index.html gets loaded when you run the applicaiton.

It is important to make sure device is ready before you try to access device properties. The API might not work correctly if the device is not ready.

As you know PhoneGap or Cordova uses JavaScript APIs to access device. It is important to notice that JavaScript can start working as soon as DOM is ready but Device needs to be ready to access device properties using JavaScript APIs.

PhoneGap or Cordova provides onDeviceReady method which gets invoked when device is ready.

Place below code in the index.html page.

<!DOCTYPE html>
   <title>Getting Started Sample</title>
   <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
   <script type="text/javascript" charset="utf-8">
      var init = function init() {
         // Wait for Cordova to load
         document.addEventListener("deviceready", onDeviceReady, false);
         // Cordova is ready
         function onDeviceReady() {
            alert("Device is ready to be used.");
      window.onload = init;

Step 8: Now run. the application and once device is ready, alert will be displayed like below.

Phonegap cordova deviceready

This ends the article of getting started with PhoneGap or Cordova in Windows Phone.

The Mobile Zone is brought to you in partnership with Strongloop and IBM.  Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud.


Published at DZone with permission of Sumit Dutta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}