PhoneGap API help documentation-Device)

Source: Internet
Author: User
Tags custom name

The device object describes the hardware and software of the device.
Attribute:
Device. name
Device. phonegap
Device. platform
Device. uuid
Device. version


Variable scope:
Because the device is assigned to the window object, it is implicitly indicated that its scope is global.

Device. name
Obtain the device model name.
Var string = device. name;
Copy code
Note:
Device. name: The device model or product name. This value is set by the device manufacturer and may vary with different versions of the same product.

Supported platforms:
Android
BlackBerry
BlackBerry WebWorks (OS 5.0 or later)
IPhone


Simple Example:
// Android: Nexus One returns "Passion" (Nexus One code name)

// Motorola Droid returns "voles"

// BlackBerry: Bold 8900 returns "8900"

// IPhone: The name set by iTunes is returned for all devices, for example, "Joe's iPhone"

Var name = device. name;
Copy code
Complete example:
<! DOCTYPE html>

<Html>

<Head>

<Title> Device Properties Example </title>

<Script type = "text/javascript" charset = "UTF-8" src = "phonegap. js"> </script>

<Script type = "text/javascript" charset = "UTF-8">

// Wait for loading PhoneGap

Document. addEventListener ("deviceready", onDeviceReady, false );

// PhoneGap loaded

Function onDeviceReady (){

Var element = document. getElementById ('deviceproperties ');

Element. innerHTML = 'device Name: '+ Device. name +' <br/> '+

'Device PhoneGap: '+ Device. phonegap +' <br/> '+

'Device Platform: '+ Device. platform +' <br/> '+

'Device UUID: '+ Device. uuid +' <br/> '+

'Device Version: '+ Device. version +' <br/> ';

}

</Script>

</Head>

<Body>

<P id = "deviceProperties"> Loading device properties... </p>

</Body>

</Html>
Copy code
Android exception:
Obtain the product name rather than the model name.

The product name is generally the code name set during the production process.
For example, Nexus One returns "Passion" and Motorola Droid returns "voles ".


IPhone exception:
Obtain the custom name of the device, not the device model name.

Custom names are customized by the owner in iTunes.

 

Device. phonegap
Obtain the running PhoneGap version on the device.
Var string = device. phonegap;
Copy code
Note:
Device. phonegap returns the version number of the running PhoneGap on the device.

Supported platforms:
Android
BlackBerry
BlackBerry WebWorks (OS 5.0 or later)
IPhone


Simple Example:
Var name = device. phonegap;
Copy code
Complete example:
<! DOCTYPE html>

<Html>

<Head>

<Title> Device Properties Example </title>

<Script type = "text/javascript" charset = "UTF-8" src = "phonegap. js"> </script>

<Script type = "text/javascript" charset = "UTF-8">

// Wait for loading PhoneGap

Document. addEventListener ("deviceready", onDeviceReady, false );

// PhoneGap loaded

Function onDeviceReady (){

Var element = document. getElementById ('deviceproperties ');

Element. innerHTML = 'device Name: '+ Device. name + ''+

'Device PhoneGap: '+ Device. phonegap + ''+

'Device Platform: '+ Device. platform + ''+

'Device UUID: '+ Device. uuid + ''+

'Device Version: '+ Device. version + '';

}

</Script>

</Head>

<Body>

<P id = "deviceProperties"> Loading device properties... </p>

</Body>

</Html>
Copy the code device. platform
Obtain the name of the operating system used by the device.

Var string = device. platform;
Copy code
Supported platforms:
Android
BlackBerry
BlackBerry WebWorks (OS 5.0 or later)
IPhone


Simple Example:
// Based on different devices, the following are some examples:

//-"Android"

//-"BlackBerry"

//-"IPhone"

//-"WebOS"

Var devicedevicePlatform = device. platform;
Copy code
Complete example:
<! DOCTYPE html>

<Html>

<Head>

<Title> Device Properties Example </title>

<Script type = "text/javascript" charset = "UTF-8" src = "phonegap. js"> </script>

<Script type = "text/javascript" charset = "UTF-8">

// Wait for loading PhoneGap

Document. addEventListener ("deviceready", onDeviceReady, false );

// PhoneGap loaded

Function onDeviceReady (){

Var element = document. getElementById ('deviceproperties ');

Element. innerHTML = 'device Name: '+ Device. name +' <br/> '+

'Device PhoneGap: '+ Device. phonegap +' <br/> '+

'Device Platform: '+ Device. platform +' <br/> '+

'Device UUID: '+ Device. uuid +' <br/> '+

'Device Version: '+ Device. version +' <br/> ';

}

</Script>

</Head>

<Body>

<P id = "deviceProperties"> Loading device properties... </p>

</Body>

</Html>
Copy code
IPhone exception:

All devices return to the iPhone, but this is not accurate because Apple has changed the operating system of the iPhone to iOS.

 

BlackBerry exception:

The device returns the platform version number instead of the platform name. For example, Storm2 9550 will return "2.13.0.95" or similar information.

 

Device. uuid

Obtain the Globally Unique Identifier (UUID) of the device ).

Var string = device. uuid;
Copy Code Description:

UUID is determined by the device manufacturer and a specific device platform or model.

Supported platforms:

 

Android

BlackBerry

BlackBerry WebWorks (OS 5.0 or later)

IPhone
Copy A simple example of the Code: // Android: returns a random 64-bit integer (as a string)

// This integer is generated when the device is started for the first time.

// BlackBerry: returns the PIN code of the device.

// This is a nine-digit unique Certificate (as a string)

// IPhone: (refer to the UIDevice class document)

// Return the hash value generated by multiple hardware device identifiers.

// This is to ensure that each device is unique and therefore cannot be associated with the user account.

Var devicedeviceID = device. uuid;
Copy the complete sample code:
<! DOCTYPE html>

<Html>

<Head>

<Title> Device Properties Example </title>

<Script type = "text/javascript" charset = "UTF-8" src = "phonegap. js"> </script>

<Script type = "text/javascript" charset = "UTF-8">

// Wait for loading PhoneGap

Document. addEventListener ("deviceready", onDeviceReady, false );

// PhoneGap loaded

Function onDeviceReady (){

Var element = document. getElementById ('deviceproperties ');

Element. innerHTML = 'device Name: '+ Device. name +' <br/> '+

'Device PhoneGap: '+ Device. phonegap +' <br/> '+

'Device Platform: '+ Device. platform +' <br/> '+

'Device UUID: '+ Device. uuid +' <br/> '+

'Device Version: '+ Device. version +' <br/> ';

}

</Script>

</Head>

<Body>

<P id = "deviceProperties"> Loading device properties... </p>

</Body>

</Html>
Copy the device. version code.
Obtain the version number of the Operating System
Var string = device. version;
Copy code
Supported platforms:
Android
BlackBerry
BlackBerry WebWorks (OS 5.0 or later)
IPhone


Simple Example:
// Android: Froyo returns 2.2

// Eclair returns 2.1, 2.01, or 2.0

// The version may also return the update level "2.1-update1"

// BlackBerry: Use the Bold 4.6 of OS 9000 to return "4.6.0.282"

// IPhone: "3.2" is returned for iOS 3.2"

Var devicedeviceVersion = device. version;
Copy code
Complete example:
<! DOCTYPE html>

<Html>

<Head>

<Title> Device Properties Example </title>

<Script type = "text/javascript" charset = "UTF-8" src = "phonegap. js"> </script>

<Script type = "text/javascript" charset = "UTF-8">

// Wait for loading PhoneGap

Document. addEventListener ("deviceready", onDeviceReady, false );

// PhoneGap loaded

Function onDeviceReady (){

Var element = document. getElementById ('deviceproperties ');

Element. innerHTML = 'device Name: '+ Device. name +' <br/> '+

'Device PhoneGap: '+ Device. phonegap +' <br/> '+

'Device Platform: '+ Device. platform +' <br/> '+

'Device UUID: '+ Device. uuid +' <br/> '+

'Device Version: '+ Device. version +' <br/> ';

}

</Script>

</Head>

<Body onload = "onLoad ()">

<P id = "deviceProperties"> Loading device properties... </p>

</Body>

</Html>
Author: LuoXianXion
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.