O'Reilly logo

Beginning PhoneGap by Thomas Myer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required