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.

311 lines
9.7 KiB

7 years ago
  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. |Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI |
  24. |:-:|:-:|:-:|:-:|:-:|:-:|
  25. |[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-device)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-device/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-device)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-device/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-device)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-device/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-device)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-device/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-device)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=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. - Amazon Fire OS
  51. - Android
  52. - BlackBerry 10
  53. - Browser
  54. - Firefox OS
  55. - iOS
  56. - Tizen
  57. - Windows Phone 7 and 8
  58. - Windows
  59. - OSX
  60. ## device.model
  61. The `device.model` returns the name of the device's model or
  62. product. The value is set by the device manufacturer and may be
  63. different across versions of the same product.
  64. ### Supported Platforms
  65. - Android
  66. - BlackBerry 10
  67. - Browser
  68. - iOS
  69. - Tizen
  70. - Windows Phone 7 and 8
  71. - Windows
  72. - OSX
  73. ### Quick Example
  74. ```js
  75. // Android: Nexus One returns "Passion" (Nexus One code name)
  76. // Motorola Droid returns "voles"
  77. // BlackBerry: Torch 9800 returns "9800"
  78. // Browser: Google Chrome returns "Chrome"
  79. // Safari returns "Safari"
  80. // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models
  81. // OSX: returns "x86_64"
  82. //
  83. var model = device.model;
  84. ```
  85. ### Android Quirks
  86. - 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`.
  87. ### Tizen Quirks
  88. - Returns the device model assigned by the vendor, for example, `TIZEN`
  89. ### Windows Phone 7 and 8 Quirks
  90. - Returns the device model specified by the manufacturer. For example, the Samsung Focus returns `SGH-i917`.
  91. ## device.platform
  92. Get the device's operating system name.
  93. ```js
  94. var string = device.platform;
  95. ```
  96. ### Supported Platforms
  97. - Android
  98. - BlackBerry 10
  99. - Browser
  100. - Firefox OS
  101. - iOS
  102. - Tizen
  103. - Windows Phone 7 and 8
  104. - Windows
  105. - OSX
  106. ### Quick Example
  107. ```js
  108. // Depending on the device, a few examples are:
  109. // - "Android"
  110. // - "BlackBerry 10"
  111. // - "browser"
  112. // - "iOS"
  113. // - "WinCE"
  114. // - "Tizen"
  115. // - "Mac OS X"
  116. var devicePlatform = device.platform;
  117. ```
  118. ### Windows Phone 7 Quirks
  119. Windows Phone 7 devices report the platform as `WinCE`.
  120. ### Windows Phone 8 Quirks
  121. Windows Phone 8 devices report the platform as `Win32NT`.
  122. ## device.uuid
  123. Get the device's Universally Unique Identifier ([UUID](http://en.wikipedia.org/wiki/Universally_Unique_Identifier)).
  124. ```js
  125. var string = device.uuid;
  126. ```
  127. ### Description
  128. The details of how a UUID is generated are determined by the device manufacturer and are specific to the device's platform or model.
  129. ### Supported Platforms
  130. - Android
  131. - BlackBerry 10
  132. - iOS
  133. - Tizen
  134. - Windows Phone 7 and 8
  135. - Windows
  136. - OSX
  137. ### Quick Example
  138. ```js
  139. // Android: Returns a random 64-bit integer (as a string, again!)
  140. // The integer is generated on the device's first boot
  141. //
  142. // BlackBerry: Returns the PIN number of the device
  143. // This is a nine-digit unique integer (as a string, though!)
  144. //
  145. // iPhone: (Paraphrased from the UIDevice Class documentation)
  146. // 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.
  147. // Windows Phone 7 : Returns a hash of device+current user,
  148. // if the user is not defined, a guid is generated and will persist until the app is uninstalled
  149. // Tizen: returns the device IMEI (International Mobile Equipment Identity or IMEI is a number
  150. // unique to every GSM and UMTS mobile phone.
  151. var deviceID = device.uuid;
  152. ```
  153. ### iOS Quirk
  154. 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.
  155. Refer [here](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/#//apple_ref/occ/instp/UIDevice/identifierForVendor) for details.
  156. 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.
  157. ### OSX Quirk
  158. The `uuid` on OSX is generated automatically if it does not exist yet and is stored in the `standardUserDefaults` in the `CDVUUID` property.
  159. ### Windows Phone 7 and 8 Quirks
  160. The `uuid` for Windows Phone 7 requires the permission
  161. `ID_CAP_IDENTITY_DEVICE`. Microsoft will likely deprecate this
  162. property soon. If the capability is not available, the application
  163. generates a persistent guid that is maintained for the duration of the
  164. application's installation on the device.
  165. ## device.version
  166. Get the operating system version.
  167. var string = device.version;
  168. ### Supported Platforms
  169. - Android 2.1+
  170. - BlackBerry 10
  171. - Browser
  172. - iOS
  173. - Tizen
  174. - Windows Phone 7 and 8
  175. - Windows
  176. - OSX
  177. ### Quick Example
  178. ```js
  179. // Android: Froyo OS would return "2.2"
  180. // Eclair OS would return "2.1", "2.0.1", or "2.0"
  181. // Version can also return update level "2.1-update1"
  182. //
  183. // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600"
  184. //
  185. // Browser: Returns version number for the browser
  186. //
  187. // iPhone: iOS 3.2 returns "3.2"
  188. //
  189. // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720
  190. // Windows 8: return the current OS version, ex on Windows 8.1 returns 6.3.9600.16384
  191. // Tizen: returns "TIZEN_20120425_2"
  192. // OSX: El Capitan would return "10.11.2"
  193. //
  194. var deviceVersion = device.version;
  195. ```
  196. ## device.manufacturer
  197. Get the device's manufacturer.
  198. var string = device.manufacturer;
  199. ### Supported Platforms
  200. - Android
  201. - BlackBerry 10
  202. - iOS
  203. - Windows Phone 7 and 8
  204. - Windows
  205. ### Quick Example
  206. ```js
  207. // Android: Motorola XT1032 would return "motorola"
  208. // BlackBerry: returns "BlackBerry"
  209. // iPhone: returns "Apple"
  210. //
  211. var deviceManufacturer = device.manufacturer;
  212. ```
  213. ## device.isVirtual
  214. whether the device is running on a simulator.
  215. ```js
  216. var isSim = device.isVirtual;
  217. ```
  218. ### Supported Platforms
  219. - Android 2.1+
  220. - iOS
  221. - Windows Phone 8
  222. - Windows
  223. - OSX
  224. ### OSX Quirk
  225. The `isVirtual` property on OS X always returns false.
  226. ## device.serial
  227. Get the device hardware serial number ([SERIAL](http://developer.android.com/reference/android/os/Build.html#SERIAL)).
  228. ```js
  229. var string = device.serial;
  230. ```
  231. ### Supported Platforms
  232. - Android
  233. - OSX