Creating Mobile applications is something a lot of web developers are keen to get into.

The problem with creating these applications when coming from a web background is that new languages need to be learned.

With PhoneGap that need is gone, PhoneGap allows you to build web applications with languages you are already familiar with like HTML, CSS and JavaScript.


PhoneGap is an open source framework that aids in the development of cross-platform applications with languages familiar to web developers.

For anyone from a web background this is a great solution and it also has the benefit of being a cross-platform approach to mobile development.

Since we all want to work with different platforms, there’s no installation guide that’s better than PhoneGap’s own guide, follow the instructions there to install PhoneGap in your preferred environment.


The good thing about working with PhoneGap is that we have access to a lot of device API’s like:

  • Accelerometer — The accelerometer allows us to tap in to the motion sensor in the mobile device.
  • Camera — We can capture a photo using the device’s camera.
  • Compass — With compass we can get the direction the device is pointing in.
  • Capture — The capture provides us access to the audio, image, and video capture capabilities of the device.
  • Connection — Check if the user has an internet connection and get its details.
  • Contacts — With this API we can access the contacts database on the device.
  • Device — This API helps us get information about the device itself.
  • File — Using the JavaScript File we can read, write and navigate through the user’s files on the device.
  • Events — This API allows us too hook up to a user event and add a callback to it. An example could be the device ready event, lowering down the sound or even hooking up a function when the user’s battery is critically low.
  • Geolocation — This API is widely used in the mobile world and it makes your application aware of where it’s located.
  • Globalization — The globalization object obtains information and executes specific functions taking into consideration the user’s locale and timezone.
  • Media — With the Media API you can record and play audio files.
  • Notification — This API gives you a way to notify the user in a visual, audible or tactile way.
  • InAppBrowser — The InAppBrowser is used to launch URL’s in a web browser.
  • Splashscreen — Enables developers to show or hide the application’s splash screen.
  • Storage — With this API you can hook into the device storage options.

As you can see using PhoneGap and the Javascript API’s there really isn’t an app you can’t build. The best thing about working with PhoneGap is that all of this is achieved in a simple manner.

If for instance, you want your app to measure the device’s motion you would use the accelerometer API. A simple example measuring three axis would look something like this:

document.addEventListener("deviceready", loaded, false);
function loaded(){
navigator.accelerometer.getCurrentAcceleration(success, error);
function success(acceleration){
'Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n'
function error(){
alert("There was an error");

As you can see the first thing we did was check if the device was ready, if that comes back true we start the accelerometer and get its current position and in there we passed a success callback and an error callback; in the former I created an alert with the acceleration in all 3 axis and in the latter just a simple error alert to let the user know that something went wrong.


In this first part we took a look at what PhoneGap is, what its capabilities are, and we even saw how to use one of its device API’s. We’ll continue with this in the second part of this tutorial where we’ll be looking at more device APIs like the camera and geolocation.

Related posts

  1. 體驗真正網上 Personal Loan 批核,隨時提款話咁易! TPF 團隊撐您,現金即時到手!自訂還款期,短期周轉首選!立即申請,特快私人貸款。 特快網上批核 | 還款計算機.

  2. 9合1升級保護,提升全面防護!!! 相比之前四合一的疫苗只能預防四種hpv病毒,70的相關癌症。 九合一可以預防9種hpv病毒,可預防高達90以上的子宮頸癌、外陰癌、陰道癌和肛門癌及癌前病變等。 HPV9合1子宮頸癌疫苗 Gardasil 功效 100 預防高危致癌的 HPV 16、18、31、33、45、52 及 58 型號 (可減低 90 患子宮頸癌、、90-95 肛門癌、85-90 外陰癌、80-85 陰道癌及相關癌前病變的風險) 100 減低引致生殖器官濕疣 (俗稱「椰菜花」) 的 HPV 6、11 型的感染 (可減低超過 90 患生殖器官濕疣的風險) 男性方面,能減低患上肛門癌、生殖器官濕疣 (俗稱「椰菜花」) 及傳播 HPV 病毒的風險 注射位置紅腫及痛、輕微發燒和頭痛,至今未有嚴重副作用記錄——新型第二代透明質酸

Leave a Reply