With the first and second parts of this tutorial we have gotten pretty far when it comes to understanding PhoneGap and in this last part we will take a look at some more device API’s that we can make use of when creating our mobile applications with PhoneGap.


The name in this API is pretty self explanatory , with this API we can access the device’s contacts database and it allows us to either create , find , clone or delete a contact.

To create a contact we need to use the contacts.create method and using that method to create a simple contact is as simple as:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var contact = navigator.contacts.create();
contact.displayName = "Jane";
contact.nickname = "Jane";
var name = new ContactName();
name.givenName = "Jane";
name.familyName = "Doe"; = name;
//Phone Numbers
var phoneNumbers = [];
phoneNumbers[0] = new ContactField('work', '212-555-1234', false);
phoneNumbers[1] = new ContactField('mobile', '917-555-5432', true);
contact.phoneNumbers = phoneNumbers;,saveError);

If we take a look at the code you can see that we first waited for the device to be ready, like we usually do when it comes to these API’s, then we use the contacts.create method and assign it to the variable called contact.

The next step was to give our contact a display name ( I also set a nickname for compatibility), in the next part we set the contact’s name and family name, this is where we can place other things like middleName, honorificPrefix and honorificSuffix.

Next we add the contact’s phone numbers, and these must be placed inside an array because one person can have various phone numbers, it’s the same idea with e-mails.

The last things we need to do is save the contact to the database and provide success and error functions where we can just place an alert or anything we please.

This was just the create method, we can also clonefind or even remove contacts from the database.


In some cases you may need the application to be aware of what connection, if any, the device is using. Whether you’re downloading a file or synchronizing data, it’s always a good idea for the app to be mindful of the type of connection.

In order to check for all types of connections and alert the proper one we’d use something like:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown';
states[Connection.ETHERNET] = 'Ethernet';
states[Connection.WIFI] = 'WiFi';
states[Connection.CELL_2G] = 'Cell 2G';
states[Connection.CELL_3G] = 'Cell 3G';
states[Connection.CELL_4G] = 'Cell 4G';
states[Connection.CELL] = 'Cell generic';
states[Connection.NONE] = 'No connection';
alert('Connection type: ' + states[networkState]);

In this piece of code, after the document has finished loading we call the checkConnectionfunction and in that function all we do is provide readable names for all types of connection so that we can alert that to the user.

The connection API is a very simple one to put into use but it’s also a very specific API , it’s not needed in all applications but is very helpful when called upon.


This will be the last API we will be talking about and with this API we can gather all the information we may need about the device our application is running on, like the OS, model and version of that OS so that if, for example, we have code that needs a certain version of Android to run we won’t run it if the test we did on the device version comes back negative. To get all the information from the device and place it on the screen we use something like:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var info = document.getElementById('info');
info.innerHTML = 'Device Model: ' + device.model + '<br />' +
'Platform: ' + device.platform + '<br />' +
'Version: ' + device.version + '<br />' +
'Cordova: ' + device.cordova + '<br />' +
'Identifier: ' + device.uuid;

In this API, after the document has finished loading, we first grab the element where we want our device info to be placed and then grab all of its characteristics; first we get the model, then the OS and its version, then the Cordova version and finally we get the device’s Universally Unique Identifier. Now we have this data we can do something useful with it like show the correct UI.


When it comes to phone applications there are literally thousands of applications for all the OS’s but the transition between creating a web app and a phone app used to be quite rough and now we can do it smoothly using all the languages we already use on our daily life.

There is still a lot of PhoneGap to discover and build upon but these three articles have been your long introduction to what it can do and just how much you can customize your application depending on the device or even location.

Now go build some great mobile applications with PhoneGap.

Related posts

  1. 住宅樓宇按揭. 住宅樓宇按揭服務適用於購買一、二手物業或轉按,加上靈活彈性的還款期,全面滿足不同客戶的資金需要。 服務要點. 適用於一、二手物業或轉按,切合 …

  2. 激光靶向祛痣:對斑痣的顯性症狀能快速控制、甚至消除,短期實現肌膚無暇;多款激光設備深層激活膠原蛋白活性,深層煥發激活生命力。快速補充肌膚活性:根據顧客肌膚特性,醫生配套無創注射項目,為肌膚注入玻尿酸、肉毒素等能直接補充肌膚活性,快速補充肌膚缺失的玻尿酸、膠原蛋白,並能達到年輕態塑型的效果,從膚質和形態上保持年輕。聯合療法:注射玻尿酸、肉毒素等產品、配合精確波長的激光能加速透明質酸、肉毒素等物質的吸收,能極大化提高注射營養物質轉換率,最高達30以上,塑形效果保持3.5個月以上,年輕態效果保持時間延長1年以上。合1子宮頸癌疫苗-Gardasil

  3. 韓國膠原蛋白提拉線,在韓國又稱作FTL(Fine Thread Lifting細線埋入拉提術)」,可達到最新趨勢V臉回春效果。它是運用獲得韓國食品藥品管理局KFDA最高安全等級認證的可吸收縫線PDO (polydioxanone)的Fine Thread(細螺紋) 埋入皮膚真皮層裡作用,利用異物反應原理,促進皮膚真皮膠原的增生、刺激局部微循環、從而提拉皮膚和肌肉,增強皮膚彈性,達到提升、除皺,美白、嫩膚等多重回春效果。康柏苗-(-蛇針-)-

  4. I’m just writing to let you be aware of what a exceptional experience my cousin’s princess found visiting your blog. She mastered a lot of pieces, including how it is like to possess an amazing teaching mindset to let certain people quite simply know a variety of complicated subject areas. You undoubtedly exceeded my expected results. Many thanks for churning out these great, safe, revealing and even cool tips about the topic to Sandra.

  5. I wanted to create you the bit of observation to help thank you yet again just for the wonderful tips you’ve documented on this page. It’s tremendously open-handed with people like you to grant without restraint what exactly a few individuals might have advertised for an e-book to help with making some profit on their own, particularly considering the fact that you might well have tried it if you wanted. The secrets as well served like the great way to recognize that most people have the same dreams just like my personal own to know the truth many more with respect to this condition. Certainly there are thousands of more pleasurable times in the future for folks who examine your website.

  6. I would like to get across my admiration for your generosity in support of men and women who need assistance with in this matter. Your special dedication to getting the solution around appears to be quite good and has specifically helped regular people just like me to reach their ambitions. Your personal helpful help and advice indicates a whole lot a person like me and still more to my office workers. Thank you; from everyone of us.

  7. I not to mention my pals appeared to be looking at the best hints located on your web site while all of the sudden I got a horrible suspicion I never thanked the site owner for those tips. Those boys appeared to be certainly thrilled to study them and have in effect without a doubt been making the most of these things. Thank you for turning out to be really thoughtful as well as for settling on varieties of fine ideas most people are really desperate to understand about. My personal sincere regret for not expressing gratitude to you sooner.

  8. I truly wanted to develop a simple note to be able to express gratitude to you for these awesome pointers you are posting on this website. My prolonged internet lookup has at the end of the day been recognized with useful details to share with my family members. I ‘d assert that we visitors are very much blessed to dwell in a really good place with so many awesome people with interesting pointers. I feel really privileged to have encountered your site and look forward to really more fabulous minutes reading here. Thank you once again for everything.

  9. I’m also writing to let you understand what a useful discovery my daughter gained visiting your webblog. She even learned too many issues, with the inclusion of what it’s like to have an amazing helping character to have other individuals effortlessly know just exactly a number of grueling subject areas. You truly did more than my desires. I appreciate you for coming up with the interesting, dependable, educational and also easy tips about your topic to Gloria.

  10. I wish to express my appreciation for your generosity in support of persons who must have help on this topic. Your very own dedication to getting the message up and down had become rather beneficial and have in every case allowed women just like me to attain their dreams. Your personal important advice implies much to me and further more to my office colleagues. Best wishes; from everyone of us.

  11. My wife and i were really lucky when Ervin managed to conclude his investigations through your ideas he made through the blog. It’s not at all simplistic to simply be giving out secrets and techniques that many other people could have been making money from. We grasp we now have the website owner to be grateful to for this. All the illustrations you made, the simple web site navigation, the friendships you help foster – it is many remarkable, and it’s helping our son in addition to us recognize that the subject matter is brilliant, which is certainly unbelievably essential. Many thanks for the whole lot!

  12. I wanted to send you that bit of word to help say thank you the moment again for the pleasant techniques you’ve shown at this time. It has been so surprisingly open-handed with people like you to provide unhampered just what a number of us could have distributed as an e-book to make some bucks for their own end, particularly since you could have tried it if you wanted. Those principles also served to be a great way to comprehend other people have the identical fervor just like mine to learn more with respect to this condition. I’m certain there are many more pleasurable periods ahead for many who view your blog post.

  13. I am also commenting to make you understand what a magnificent experience my friend’s girl gained viewing your webblog. She even learned many pieces, which included what it’s like to have an excellent helping heart to get the mediocre ones effortlessly thoroughly grasp several problematic matters. You actually did more than my expected results. Thank you for supplying the good, trusted, edifying and as well as unique tips on the topic to Mary.

  14. Thank you for each of your labor on this blog. Gloria really likes carrying out research and it’s really easy to see why. A number of us learn all regarding the powerful manner you offer helpful suggestions via this website and as well improve response from other individuals on that subject so our own daughter is actually discovering so much. Take advantage of the remaining portion of the new year. You’re doing a useful job.

  15. I in addition to my pals appeared to be reading through the great guides located on your web site then the sudden got an awful feeling I never thanked you for them. These people had been totally happy to read through all of them and have now definitely been making the most of these things. Thanks for indeed being quite thoughtful and also for selecting this kind of terrific tips most people are really desirous to learn about. Our honest apologies for not expressing appreciation to earlier.

  16. Needed to write you one little bit of word so as to say thanks as before considering the magnificent tactics you’ve contributed on this website. It is quite strangely generous with you to present unhampered precisely what many people could have sold for an ebook to help with making some dough for their own end, most importantly now that you might have tried it if you ever desired. These points additionally worked to provide a easy way to be sure that the rest have a similar keenness just as mine to figure out many more concerning this issue. I’m certain there are thousands of more pleasurable periods ahead for those who scan through your site.

Leave a Reply