Presentation is loading. Please wait.

Presentation is loading. Please wait.

Device,Network, Vibration, Console, Accelerometer

Similar presentations


Presentation on theme: "Device,Network, Vibration, Console, Accelerometer"— Presentation transcript:

1 Device,Network, Vibration, Console, Accelerometer
CIS 136 Building Mobile Apps

2 Device

3 Device Plug-in describes the device's hardware and software
Global in scope, but not available until the device is ready Device Plug-in has 5 properties cordova model platform uuid Version Manufacturer isVirtual serial

4 Device Plug-in cordova property
Gets the version of Cordova running on the device $(document).on(“deviceready", function() { $(‘#info’).html(device.cordova); });

5 Device Plug-in platform property
Gets the operating system name "Android" "BlackBerry 10" "browser" "iOS" "WinCE" "Tizen" "Mac OS X" $(document).on(“deviceready", function() { $(‘info’).html(device.platform); });

6 Device Plug-in manufacturer property
Gets the Manufacturer Android: Motorola XT1032 would return "motorola" BlackBerry: returns "BlackBerry" iPhone: returns "Apple" $(document).on(“deviceready", function() { $(‘info’).html(device.manufacturer); }

7 Device Plug-in model property
Gets the name of the device's model or product set by the device manufacturer and may be different across versions of the same product Might get the production code name Android: Nexus One returns "Passion" (Nexus One code name) Motorola Droid returns "voles" iOS: for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1 $(document).on(“deviceready", function() { $(‘info’).html(device.model); });

8 Device Plug-in uuid property
Gets the Universally Unique Identifier a 128-bit value that is ‘practically unique’ determined by the device manufacturer and are specific to the device's platform or model. $(document).on(“deviceready", function() { $(‘info’).html(device.uuid); });

9 Device Plug-in version property
Gets the operating system version Android: Pie OS would return “9.0" Lollipop OS would return “5.0“ or “5.1.1 iPhone: iOS returns “12.2" Windows Phone : Windows 10 Mobile, version 1709 (after 12/10/19 windows mobile will be discontinued) $(document).on(“deviceready", function() { $(‘info’).html(device.version); });

10 Device Plug-in isVirtual property
Determines whether the device is running on a emulator $(document).on(“deviceready", function() { $(‘info’).html(device.isVirtual); };

11 Device Plug-in serial property
Gets the serial number $(document).on(“deviceready", function() { $(‘info’).html(device.serial); });

12 Console

13 Cordova Console Plugin
log() – writes messages to the console $(document).on("deviceready", function() { console.log(“message to console – Hello there”); });

14 Network

15 Network Information Plug-in Navigator.connection
provides information about the device's cellular and wifi connection Indicates if the device has an internet connection Connection Object has 1 property, connection.type which has values: "bluetooth“ "cellular“ "ethernet“ "mixed“ "none“ "other“ "unknown“ "wifi“ "wimax“ If cellular, the connection.effectiveType property will distinguish between "2g", "3g", "4g", and "slow-2g"

16 navigator.connection.type determine the device's type of connection
Ex: $(document).on(“deviceready", function() { var nettype = navigator.connection.type; $(‘info’).html(nettype); });

17 Network related events
offline - fires when an application goes offline, and the device is not connected to the Internet $(document).on(“offline", function() { }); online - fires when an application goes online, and the device becomes connected to the Internet $(document).on(“online", function()

18 Vibration

19 Vibration Plug-in provides a way to vibrate the device using the navigator.vibrate() method Parameters passed to it alter the vibration pattern One long vibration Syntax: navigator.vibrate(duration) where duration is specified in milliseconds Example: navigator.vibrate(2000); Several vibrations with a pause in between : Syntax: navigator.vibrate(duration,pause[,duration,pause,duration,pause, etc]) Example: navigator.vibrate([1000,2000,3000,1000,5000]);

20 Vibration Plug-in Cancel Vibration: Pass in a parameter of 0, an empty array, or an array with one element of value 0  navigator.vibrate(0) navigator.vibrate([]) navigator.vibrate([0])

21 Accelerometer

22 Accelerometer Modern mobile phones come with a variety of sensors that automate many of our daily tasks Accelerometers in mobile phones are used to measure the tilting motion and orientation of a mobile phone Applications: When you use a compass app on your smartphone, it somehow knows which direction the phone is pointing Apps that calculate the steps you take whether you’re walking, jogging or running Detection of earthquakes

23 Accelerometer the device's accelerometer is a motion sensor that detects the change (delta) in movement relative to the current device orientation, in three dimensions along the x, y, and z axis Methods navigator.accelerometer.getCurrentAcceleration() navigator.accelerometer.watchAcceleration() navigator.accelerometer.clearWatch() Has success and fail callbacks If the method is successful, it returns an acceleration data object If the method fails, it returns an error object

24 Acceleration data object
data captured at a specific point in time Acceleration values include the effect of gravity (9.81 m/s^2), so that when a device lies flat and facing up, x, y, and z values returned should be 0, 0, and 9.81. Properties x: Amount of acceleration on the x-axis. (in m/s^2) (Number) y: Amount of acceleration on the y-axis. (in m/s^2) (Number) z: Amount of acceleration on the z-axis. (in m/s^2) (Number) timestamp: Creation timestamp in milliseconds. (DOMTimeStamp)

25 Accelerometer – getCurrentAcceleration()
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError); function onSuccess(acceleration) { alert('Acceleration X: ' + acceleration.x + 'Acceleration Y: ' + acceleration.y + 'Acceleration Z: ' + acceleration.z + 'Timestamp: ' acceleration.timestamp ); }; function onError(error) { alert(“an error occurred – “ + error.code);

26 Accelerometer – watchAcceleration()
Retrieves the device's current Acceleration at a regular interval Executes the Success callback function each time Specify the interval in milliseconds via the Options object's frequency parameter Returns a watch ID which references the accelerometer's watch interval, and can be used with navigator.accelerometer.clearWatch to stop watching the accelerometer. var watchID = navigator.accelerometer.watchAcceleration(onSuccess,onError,options); options period: requested period of calls to accelerometerSuccess with acceleration data in Milliseconds. (Number) (Default: 10000)

27 Accelerometer – watchAcceleration() - example
var options = { frequency: 3000 }; // Update every 3 seconds var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options); function onSuccess(acceleration) { alert('Acceleration X: ' + acceleration.x + 'Acceleration Y: ' + acceleration.y + 'Acceleration Z: ' + acceleration.z + 'Timestamp: ' acceleration.timestamp ); }; function onError() { alert(‘An Error occurred!');

28 Accelerometer – clear watch
Stop watching the Acceleration being watched navigator.accelerometer.clearWatch(watchID); var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options); // ... later on ...


Download ppt "Device,Network, Vibration, Console, Accelerometer"

Similar presentations


Ads by Google