Touchgui/plugins/org.apache.cordova.device/doc/index.md

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

michael@0 1 <!---
michael@0 2 Licensed to the Apache Software Foundation (ASF) under one
michael@0 3 or more contributor license agreements. See the NOTICE file
michael@0 4 distributed with this work for additional information
michael@0 5 regarding copyright ownership. The ASF licenses this file
michael@0 6 to you under the Apache License, Version 2.0 (the
michael@0 7 "License"); you may not use this file except in compliance
michael@0 8 with the License. You may obtain a copy of the License at
michael@0 9
michael@0 10 http://www.apache.org/licenses/LICENSE-2.0
michael@0 11
michael@0 12 Unless required by applicable law or agreed to in writing,
michael@0 13 software distributed under the License is distributed on an
michael@0 14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0 15 KIND, either express or implied. See the License for the
michael@0 16 specific language governing permissions and limitations
michael@0 17 under the License.
michael@0 18 -->
michael@0 19
michael@0 20 # org.apache.cordova.device
michael@0 21
michael@0 22 This plugin defines a global `device` object, which describes the device's hardware and software.
michael@0 23 Although the object is in the global scope, it is not available until after the `deviceready` event.
michael@0 24
michael@0 25 document.addEventListener("deviceready", onDeviceReady, false);
michael@0 26 function onDeviceReady() {
michael@0 27 console.log(device.cordova);
michael@0 28 }
michael@0 29
michael@0 30 ## Installation
michael@0 31
michael@0 32 cordova plugin add org.apache.cordova.device
michael@0 33
michael@0 34 ## Properties
michael@0 35
michael@0 36 - device.cordova
michael@0 37 - device.model
michael@0 38 - device.platform
michael@0 39 - device.uuid
michael@0 40 - device.version
michael@0 41
michael@0 42 ## device.cordova
michael@0 43
michael@0 44 Get the version of Cordova running on the device.
michael@0 45
michael@0 46 ### Supported Platforms
michael@0 47
michael@0 48 - Amazon Fire OS
michael@0 49 - Android
michael@0 50 - BlackBerry 10
michael@0 51 - Browser
michael@0 52 - Firefox OS
michael@0 53 - iOS
michael@0 54 - Tizen
michael@0 55 - Windows Phone 7 and 8
michael@0 56 - Windows 8
michael@0 57
michael@0 58 ## device.model
michael@0 59
michael@0 60 The `device.model` returns the name of the device's model or
michael@0 61 product. The value is set by the device manufacturer and may be
michael@0 62 different across versions of the same product.
michael@0 63
michael@0 64 ### Supported Platforms
michael@0 65
michael@0 66 - Android
michael@0 67 - BlackBerry 10
michael@0 68 - Browser
michael@0 69 - iOS
michael@0 70 - Tizen
michael@0 71 - Windows Phone 7 and 8
michael@0 72 - Windows 8
michael@0 73
michael@0 74 ### Quick Example
michael@0 75
michael@0 76 // Android: Nexus One returns "Passion" (Nexus One code name)
michael@0 77 // Motorola Droid returns "voles"
michael@0 78 // BlackBerry: Torch 9800 returns "9800"
michael@0 79 // Browser: Google Chrome returns "Chrome"
michael@0 80 // Safari returns "Safari"
michael@0 81 // iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models
michael@0 82 //
michael@0 83 var model = device.model;
michael@0 84
michael@0 85 ### Android Quirks
michael@0 86
michael@0 87 - 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`.
michael@0 88
michael@0 89 ### Tizen Quirks
michael@0 90
michael@0 91 - Returns the device model assigned by the vendor, for example, `TIZEN`
michael@0 92
michael@0 93 ### Windows Phone 7 and 8 Quirks
michael@0 94
michael@0 95 - Returns the device model specified by the manufacturer. For example, the Samsung Focus returns `SGH-i917`.
michael@0 96
michael@0 97 ## device.platform
michael@0 98
michael@0 99 Get the device's operating system name.
michael@0 100
michael@0 101 var string = device.platform;
michael@0 102
michael@0 103 ### Supported Platforms
michael@0 104
michael@0 105 - Android
michael@0 106 - BlackBerry 10
michael@0 107 - Browser4
michael@0 108 - Firefox OS
michael@0 109 - iOS
michael@0 110 - Tizen
michael@0 111 - Windows Phone 7 and 8
michael@0 112 - Windows 8
michael@0 113
michael@0 114 ### Quick Example
michael@0 115
michael@0 116 // Depending on the device, a few examples are:
michael@0 117 // - "Android"
michael@0 118 // - "BlackBerry 10"
michael@0 119 // - Browser: returns "MacIntel" on Mac
michael@0 120 // returns "Win32" on Windows
michael@0 121 // - "iOS"
michael@0 122 // - "WinCE"
michael@0 123 // - "Tizen"
michael@0 124 var devicePlatform = device.platform;
michael@0 125
michael@0 126 ### Windows Phone 7 Quirks
michael@0 127
michael@0 128 Windows Phone 7 devices report the platform as `WinCE`.
michael@0 129
michael@0 130 ### Windows Phone 8 Quirks
michael@0 131
michael@0 132 Windows Phone 8 devices report the platform as `Win32NT`.
michael@0 133
michael@0 134 ## device.uuid
michael@0 135
michael@0 136 Get the device's Universally Unique Identifier ([UUID](http://en.wikipedia.org/wiki/Universally_Unique_Identifier)).
michael@0 137
michael@0 138 var string = device.uuid;
michael@0 139
michael@0 140 ### Description
michael@0 141
michael@0 142 The details of how a UUID is generated are determined by the device manufacturer and are specific to the device's platform or model.
michael@0 143
michael@0 144 ### Supported Platforms
michael@0 145
michael@0 146 - Android
michael@0 147 - BlackBerry 10
michael@0 148 - iOS
michael@0 149 - Tizen
michael@0 150 - Windows Phone 7 and 8
michael@0 151 - Windows 8
michael@0 152
michael@0 153 ### Quick Example
michael@0 154
michael@0 155 // Android: Returns a random 64-bit integer (as a string, again!)
michael@0 156 // The integer is generated on the device's first boot
michael@0 157 //
michael@0 158 // BlackBerry: Returns the PIN number of the device
michael@0 159 // This is a nine-digit unique integer (as a string, though!)
michael@0 160 //
michael@0 161 // iPhone: (Paraphrased from the UIDevice Class documentation)
michael@0 162 // Returns a string of hash values created from multiple hardware identifies.
michael@0 163 // It is guaranteed to be unique for every device and can't be tied
michael@0 164 // to the user account.
michael@0 165 // Windows Phone 7 : Returns a hash of device+current user,
michael@0 166 // if the user is not defined, a guid is generated and will persist until the app is uninstalled
michael@0 167 // Tizen: returns the device IMEI (International Mobile Equipment Identity or IMEI is a number
michael@0 168 // unique to every GSM and UMTS mobile phone.
michael@0 169 var deviceID = device.uuid;
michael@0 170
michael@0 171 ### iOS Quirk
michael@0 172
michael@0 173 The `uuid` on iOS is not unique to a device, but varies for each
michael@0 174 application, for each installation. It changes if you delete and
michael@0 175 re-install the app, and possibly also when you upgrade iOS, or even
michael@0 176 upgrade the app per version (apparent in iOS 5.1). The `uuid` is not
michael@0 177 a reliable value.
michael@0 178
michael@0 179 ### Windows Phone 7 and 8 Quirks
michael@0 180
michael@0 181 The `uuid` for Windows Phone 7 requires the permission
michael@0 182 `ID_CAP_IDENTITY_DEVICE`. Microsoft will likely deprecate this
michael@0 183 property soon. If the capability is not available, the application
michael@0 184 generates a persistent guid that is maintained for the duration of the
michael@0 185 application's installation on the device.
michael@0 186
michael@0 187 ## device.version
michael@0 188
michael@0 189 Get the operating system version.
michael@0 190
michael@0 191 var string = device.version;
michael@0 192
michael@0 193 ### Supported Platforms
michael@0 194
michael@0 195 - Android 2.1+
michael@0 196 - BlackBerry 10
michael@0 197 - Browser
michael@0 198 - iOS
michael@0 199 - Tizen
michael@0 200 - Windows Phone 7 and 8
michael@0 201 - Windows 8
michael@0 202
michael@0 203 ### Quick Example
michael@0 204
michael@0 205 // Android: Froyo OS would return "2.2"
michael@0 206 // Eclair OS would return "2.1", "2.0.1", or "2.0"
michael@0 207 // Version can also return update level "2.1-update1"
michael@0 208 //
michael@0 209 // BlackBerry: Torch 9800 using OS 6.0 would return "6.0.0.600"
michael@0 210 //
michael@0 211 // Browser: Returns version number for the browser
michael@0 212 //
michael@0 213 // iPhone: iOS 3.2 returns "3.2"
michael@0 214 //
michael@0 215 // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720
michael@0 216 // Tizen: returns "TIZEN_20120425_2"
michael@0 217 var deviceVersion = device.version;
michael@0 218

mercurial