Chapter 5

Working with the Device, the Network, and Notifications

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Discovering information about your device
  • Determining the network status
  • Creating custom notifications

In Chapter 4, you learned about PhoneGap life cycle events — how to tell when the device was ready, how to pause and resume your application, and how to tell whether certain buttons were pressed on an Android device.

In this chapter, you take the next logical step and learn more about the device itself, network connectivity, and custom notifications.

GETTING INFORMATION FROM THE DEVICE

PhoneGap has a runtime object called device that holds useful information about the device. Following are the elements of device:

  • device.name — The name of the device (for example, my iPhone)
  • device.phonegap — The version of PhoneGap
  • device.platform — The type of device, (for example, iPhone)
  • device.uuid — The unique number of the device
  • device.Version — The version of the OS that is running

It’s important to note that device is assigned to the window object, so it is implicitly in the global scope. In other words, both of the following variables reference the same device:

//both of these reference the same device
var myPhoneName = window.device.name;
var myPhoneName = device.name;

In this section, you learn how to get the following:

  • The device’s name
  • The PhoneGap version
  • The device’s platform
  • The device’s Universally Unique Identifier (UUID)
  • The device’s operating system version

Getting ...

Get Beginning PhoneGap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.