Javatpoint Logo
Javatpoint Logo

Device Plugin

In our previous section, we learned lots of interesting topics about PhoneGap. Now, in this section, we will talk about the device hardware. We don't know what type of hardware our application will run on. We can get some information about the hardware and use it in our program. In this section, we will learn about the device information plugins, which tells us about the device and on which device our application is running. After that, we will learn about the device orientation which will tell us which way the device is facing, the network information plugin which will tell us about the network on which our device is connected, and battery status plugin to check the battery status before we do some type of advance or lengthy operation in PhoneGap in another section.

Now, we will use the following steps to work with the device plugin and get the device information:

Note: Different manufactures may or may not allow us to implement certain sections for security reasons.

1) Create a new project

Firstly, we will create a new PhoneGap project with a blank template. If you don't know how to create an app with a blank template, go through the PhoneGap project link.

Device Plugin

2) Create window.onload function

After creating a new project successfully, we will create the window.onload function below the title of the project. In this function, we will get the version of Cordova which our application uses in the following way:

3) Create a field for the result

Now, we will create a field for result using the <div></div> tag. JavaScript doesn't know the HTML tag. So, we will give it an id to access it in our onload function.

4) Create an output string

Now, we will create an output string for looking at a lot of the available information. We will create a string variable and then add all the information in it. After that we will show the result on the result div in the following way:


Device Plugin

After that, we will add the following information in this string variable using line break:

1) We can also get the information about the device model if the manufacturer of our device and the particular Android allows it. We will get the device model using the device.model and add it to the output string in the following way:


Device Plugin

2) We can also get information about the device platform. We will get the device platform using the device.platform and add it to the output string in the following way:


Device Plugin

3) We can get the UUID, i.e., Universal Unique Identifier. We will get the UUID using the device.uuid and add it to the output string in the following way:


Device Plugin

4) We can get the information about the version of our device. We will get the device version using the device.version and add it to the output string in the following way:


Device Plugin

5) We can get information about the manufacturer of our device. We will get the device manufacturer using the device.version and add it to the output string in the following way:


Device Plugin

6) We can also get the serial number of our mobile devices. We will get the serial number using the device.serial and add it to the output string in the following way:


Device Plugin

Complete Code

Output

Device Plugin





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA