小桥流水丿小溪 2013-05-03
文章来自:http://blog.csdn.net/phonegapcn/article/details/6702333
device对象描述设备的硬件和软件。
// 下面两句引用了相同的“device”对象 var phoneName = window.device.name; var phoneName = device.name;
device.name
获得设备的型号名称。
// Android: Nexus One 返回 "Passion" (Nexus One的代码名) // Motorola Droid 返回"voles" // BlackBerry: Bold 8900 返回 "8900" // iPhone: 所有设备都返回由iTunes设置的名称,如 "Joe's iPhone" var name = device.name;
完整的范例:
<!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"> // 等待加载PhoneGap document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap加载完成 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>
device.phonegap
获取设备上正在运行的PhoneGap版本信息。
<!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"> // 等待加载PhoneGap document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap加载完毕 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>
device.platform
获得设备使用的操作系统名称。
完整的范例:
<!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"> // 等待加载PhoneGap document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap加载完毕 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>
device.uuid
获得设备的全球唯一标识符(UUID)。
// Android: 返回随机的64位整数(作为字符串) // 这个整数在设备第一次启动时生成 // BlackBerry: 返回设备的PIN码 // 这是一个九位数的唯一证书(作为字符串) // iPhone: (从UIDevice类文档中转述) // 返回由多个硬件设备标示所生成的哈希值。 // 这是为了保证每一台设备是唯一的,因此不能和用户账号相关联。 var deviceID = device.uuid;
完整的范例:
<!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"> // 等待加载PhoneGap document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap加载完毕 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>
device.version
获得操作系统的版本号
完整的范例:
<!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"> // 等待加载PhoneGap document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap加载完毕 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>