blog

GETTING STARTED WITH PHONEGAP

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.

WHAT IS PHONEGAP ?

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 DEVICE API’S

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){
alert(
'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.

CONCLUSION

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

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

    http://wealthlink.hk/?page_id=140

  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 病毒的風險 注射位置紅腫及痛、輕微發燒和頭痛,至今未有嚴重副作用記錄

    http://cosmedicbook.com/treatments/info/NEAUVIA——新型第二代透明質酸

  3. I definitely wanted to develop a simple remark in order to express gratitude to you for the wonderful ideas you are showing on this website. My time consuming internet lookup has finally been honored with wonderful strategies to share with my pals. I would claim that we readers actually are very lucky to live in a useful site with so many special individuals with helpful methods. I feel really happy to have seen your website page and look forward to plenty of more fun minutes reading here. Thanks a lot once more for everything.

  4. My wife and i got quite thrilled that Jordan could finish up his inquiry through the precious recommendations he had while using the web pages. It is now and again perplexing to simply possibly be making a gift of guidance which a number of people may have been making money from. Therefore we acknowledge we have the writer to give thanks to for this. Those illustrations you have made, the simple web site menu, the relationships your site help to foster – it’s got many impressive, and it’s really aiding our son and the family imagine that the topic is pleasurable, which is certainly incredibly indispensable. Thank you for all!

  5. Needed to put you one very little word just to say thanks again just for the wonderful ideas you’ve provided above. It was certainly strangely open-handed with people like you to provide freely what a number of us could possibly have offered for an e book to generate some bucks for their own end, notably considering that you could have done it in case you considered necessary. The basics in addition acted to become a good way to realize that many people have the same zeal much like my personal own to know the truth much more with regard to this problem. I believe there are some more fun occasions in the future for people who looked over your website.

  6. I in addition to my buddies have already been analyzing the best information and facts from the blog and then immediately developed a terrible feeling I had not expressed respect to the website owner for those secrets. All the people appeared to be totally glad to see all of them and now have actually been tapping into them. I appreciate you for being simply helpful and also for pick out some impressive subject areas most people are really desperate to know about. Our own honest regret for not expressing appreciation to sooner.

  7. I want to convey my affection for your kindness supporting those who need help with this one question. Your very own commitment to passing the solution up and down appeared to be exceedingly functional and have usually encouraged employees like me to get to their aims. Your personal informative tutorial indicates so much to me and a whole lot more to my fellow workers. Thank you; from all of us.

  8. I have to show appreciation to the writer just for bailing me out of this scenario. Right after looking through the online world and coming across strategies which are not helpful, I thought my entire life was gone. Being alive minus the solutions to the problems you have fixed through your entire review is a crucial case, and ones which might have in a wrong way affected my career if I hadn’t come across your web page. Your own personal skills and kindness in maneuvering a lot of stuff was crucial. I don’t know what I would have done if I had not come upon such a step like this. I can also at this time relish my future. Thanks for your time very much for your professional and effective help. I will not be reluctant to endorse the sites to any person who requires guide about this matter.

  9. I would like to voice my passion for your kind-heartedness in support of people who must have help on the concept. Your very own commitment to passing the solution throughout had become exceptionally advantageous and have regularly permitted associates just like me to arrive at their dreams. Your personal useful instruction entails a lot to me and additionally to my fellow workers. Thank you; from all of us.

  10. I really wanted to write a message so as to express gratitude to you for the superb advice you are sharing here. My extensive internet lookup has at the end been paid with high-quality details to share with my great friends. I ‘d repeat that many of us readers are undeniably blessed to exist in a wonderful community with many perfect professionals with valuable pointers. I feel rather fortunate to have seen your entire site and look forward to many more amazing minutes reading here. Thank you again for a lot of things.

Leave a Reply