You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 7.5 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. ---
  2. title: Device
  3. description: Get device information.
  4. ---
  5. <!--
  6. # license: Licensed to the Apache Software Foundation (ASF) under one
  7. # or more contributor license agreements. See the NOTICE file
  8. # distributed with this work for additional information
  9. # regarding copyright ownership. The ASF licenses this file
  10. # to you under the Apache License, Version 2.0 (the
  11. # "License"); you may not use this file except in compliance
  12. # with the License. You may obtain a copy of the License at
  13. #
  14. # http://www.apache.org/licenses/LICENSE-2.0
  15. #
  16. # Unless required by applicable law or agreed to in writing,
  17. # software distributed under the License is distributed on an
  18. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. # KIND, either express or implied. See the License for the
  20. # specific language governing permissions and limitations
  21. # under the License.
  22. -->
  23. |AppVeyor|Travis CI|
  24. |:-:|:-:|
  25. |[![Build status](https://ci.appveyor.com/api/projects/status/github/apache/cordova-plugin-device?branch=master)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-plugin-device)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-device.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-device)|
  26. # cordova-plugin-device
  27. This plugin defines a global `device` object, which describes the device's hardware and software.
  28. Although the object is in the global scope, it is not available until after the `deviceready` event.
  29. ```js
  30. document.addEventListener("deviceready", onDeviceReady, false);
  31. function onDeviceReady() {
  32. console.log(device.cordova);
  33. }
  34. ```
  35. Report issues with this plugin on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Device%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
  36. ## Installation
  37. cordova plugin add cordova-plugin-device
  38. ## Properties
  39. - device.cordova
  40. - device.model
  41. - device.platform
  42. - device.uuid
  43. - device.version
  44. - device.manufacturer
  45. - device.isVirtual
  46. - device.serial
  47. ## device.cordova
  48. Get the version of Cordova running on the device.
  49. ### Supported Platforms
  50. - Android
  51. - Browser
  52. - iOS
  53. - Windows
  54. - OSX
  55. ## device.model
  56. The `device.model` returns the name of the device's model or
  57. product. The value is set by the device manufacturer and may be
  58. different across versions of the same product.
  59. ### Supported Platforms
  60. - Android
  61. - Browser
  62. - iOS
  63. - Windows
  64. - OSX
  65. ### Quick Example
  66. ```js
  67. // Android: Nexus One returns "Passion" (Nexus One code name)
  68. // Motorola Droid returns "voles"
  69. // BlackBerry: Torch 9800 returns "9800"
  70. // Browser: Google Chrome returns "Chrome"
  71. // Safari returns "Safari"
  72. // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models
  73. // OSX: returns "x86_64"
  74. //
  75. var model = device.model;
  76. ```
  77. ### Android Quirks
  78. - Gets the [product name](http://developer.android.com/reference/android/os/Build.html#PRODUCT) instead of the [model name](http://developer.android.com/reference/android/os/Build.html#MODEL), which is often the production code name. For example, the Nexus One returns `Passion`, and Motorola Droid returns `voles`.
  79. ## device.platform
  80. Get the device's operating system name.
  81. ```js
  82. var string = device.platform;
  83. ```
  84. ### Supported Platforms
  85. - Android
  86. - Browser
  87. - iOS
  88. - Windows
  89. - OSX
  90. ### Quick Example
  91. ```js
  92. // Depending on the device, a few examples are:
  93. // - "Android"
  94. // - "BlackBerry 10"
  95. // - "browser"
  96. // - "iOS"
  97. // - "WinCE"
  98. // - "Tizen"
  99. // - "Mac OS X"
  100. var devicePlatform = device.platform;
  101. ```
  102. ## device.uuid
  103. Get the device's Universally Unique Identifier ([UUID](http://en.wikipedia.org/wiki/Universally_Unique_Identifier)).
  104. ```js
  105. var string = device.uuid;
  106. ```
  107. ### Description
  108. The details of how a UUID is generated are determined by the device manufacturer and are specific to the device's platform or model.
  109. ### Supported Platforms
  110. - Android
  111. - iOS
  112. - Windows
  113. - OSX
  114. ### Quick Example
  115. ```js
  116. // Android: Returns a random 64-bit integer (as a string, again!)
  117. // The integer is generated on the device's first boot
  118. //
  119. // BlackBerry: Returns the PIN number of the device
  120. // This is a nine-digit unique integer (as a string, though!)
  121. //
  122. // iPhone: (Paraphrased from the UIDevice Class documentation)
  123. // Returns the [UIDevice identifierForVendor] UUID which is unique and the same for all apps installed by the same vendor. However the UUID can be different if the user deletes all apps from the vendor and then reinstalls it.
  124. // Windows Phone 7 : Returns a hash of device+current user,
  125. // if the user is not defined, a guid is generated and will persist until the app is uninstalled
  126. // Tizen: returns the device IMEI (International Mobile Equipment Identity or IMEI is a number
  127. // unique to every GSM and UMTS mobile phone.
  128. var deviceID = device.uuid;
  129. ```
  130. ### iOS Quirk
  131. The `uuid` on iOS uses the identifierForVendor property. It is unique to the device across the same vendor, but will be different for different vendors and will change if all apps from the vendor are deleted and then reinstalled.
  132. Refer [here](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/#//apple_ref/occ/instp/UIDevice/identifierForVendor) for details.
  133. The UUID will be the same if app is restored from a backup or iCloud as it is saved in preferences. Users using older versions of this plugin will still receive the same previous UUID generated by another means as it will be retrieved from preferences.
  134. ### OSX Quirk
  135. The `uuid` on OSX is generated automatically if it does not exist yet and is stored in the `standardUserDefaults` in the `CDVUUID` property.
  136. ## device.version
  137. Get the operating system version.
  138. var string = device.version;
  139. ### Supported Platforms
  140. - Android 2.1+
  141. - Browser
  142. - iOS
  143. - Windows
  144. - OSX
  145. ### Quick Example
  146. ```js
  147. // Android: Froyo OS would return "2.2"
  148. // Eclair OS would return "2.1", "2.0.1", or "2.0"
  149. // Version can also return update level "2.1-update1"
  150. //
  151. // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600"
  152. //
  153. // Browser: Returns version number for the browser
  154. //
  155. // iPhone: iOS 3.2 returns "3.2"
  156. //
  157. // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720
  158. // Windows 8: return the current OS version, ex on Windows 8.1 returns 6.3.9600.16384
  159. // Tizen: returns "TIZEN_20120425_2"
  160. // OSX: El Capitan would return "10.11.2"
  161. //
  162. var deviceVersion = device.version;
  163. ```
  164. ## device.manufacturer
  165. Get the device's manufacturer.
  166. var string = device.manufacturer;
  167. ### Supported Platforms
  168. - Android
  169. - iOS
  170. - Windows
  171. ### Quick Example
  172. ```js
  173. // Android: Motorola XT1032 would return "motorola"
  174. // BlackBerry: returns "BlackBerry"
  175. // iPhone: returns "Apple"
  176. //
  177. var deviceManufacturer = device.manufacturer;
  178. ```
  179. ## device.isVirtual
  180. whether the device is running on a simulator.
  181. ```js
  182. var isSim = device.isVirtual;
  183. ```
  184. ### Supported Platforms
  185. - Android 2.1+
  186. - Browser
  187. - iOS
  188. - Windows
  189. - OSX
  190. ### OSX and Browser Quirk
  191. The `isVirtual` property on OS X and Browser always returns false.
  192. ## device.serial
  193. Get the device hardware serial number ([SERIAL](http://developer.android.com/reference/android/os/Build.html#SERIAL)).
  194. ```js
  195. var string = device.serial;
  196. ```
  197. ### Supported Platforms
  198. - Android
  199. - OSX