Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 1
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 2
Integrating Device Services with ADF Mobile
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 3
Apache Cordova / PhoneGap
ADF Mobile utilizes PhoneGap to access most of the onboard devices
services
– To be replaced by Apache Cordova soon
Provides access to:
– Device Properties
– SMS and Email (Not through PhoneGap)
– Contacts
– Camera and Photo Library
– Geolocation
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 4
Overview Accessing Device Services
2. Implicit EL Objects
3. Programmatic APIs
1. Data Controls
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 5
Overview Accessing Device Services
2. Implicit EL Objects
3. Programmatic APIs
1. Data Controls
Found in the Data Control Palette
Drag n drop services onto a page
Take the grunt work out of coding
calls to the API and constructing
the necessary screens
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 6
Overview Accessing Device Services
2. Implicit EL Objects
3. Programmatic APIs
1. Data Controls
Provide easy access to device
properties
Referenced via the UI components
Simply type or use the Expression
Builder
#{deviceScope.device.hasContacts}
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 7
Overview Accessing Device Services
2. Implicit EL Objects
3. Programmatic APIs
1. Data Controls
Provide programmers the flexibility of accessing device services
from Java with their own Java Beans
Easier to handle error conditions and process any outputs
DeviceManager dm = DeviceManagerFactory.getDeviceManager();
dm.sendEmail("[email protected]","[email protected]",
"Test email", "Test message", null, null, null);
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 8
Device Service Accessible from JavaScript
Access device services from non AMX pages
– Remote URL
– Local HTML
Add JavaScript library to your page
Direct access to invoke device features
Use adf.mf.api.*
– adf.mf.api.sendSMS({to: "5551234567", body: "This is a test message"});
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 9
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 10
Accessing Device Properties
Service Data Control EL Access Programmatic
Device Properties Yes Yes
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 11
Property Static/Dyna
mic EL Expression Sample Value Java API
device.name Static #{deviceScope.device.name} "Joe Smith's iPhone" DeviceManager.getName()
device.platform Static #{deviceScope.device.platform} "iPhone" DeviceManager.getPlatform()
device.version Static #{deviceScope.device.version} "4.3.2", "5.0.1" DeviceManager.getVersion()
device.os Static #{deviceScope.device.os} "iOS" DeviceManager.getOs()
device.model Static #{deviceScope.device.model} "i386", "iPhone3,1" DeviceManager.getModel()
device.phonegap Static #{deviceScope.device.phonegap} "1.0.0" DeviceManager.getPhonegap()
hardware.hasCamera Static #{deviceScope.hardware.hasCamera} true, false DeviceManager.hasCamera()
hardware.hasContacts Static #{deviceScope.hardware.hasContacts} true, false DeviceManager.hasContacts()
hardware.hasTouchScreen Static #{deviceScope.hardware.hasTouchScreen} true, false DeviceManager.hasTouchScreen()
hardware.hasGeolocation Static #{deviceScope.hardware.hasGeolocation} true, false DeviceManager.hasGeolocation()
hardware.hasAccelerometer Static #{deviceScope.hardware.hasAccelerometer} true, false DeviceManager.hasAccelerometer()
hardware.hasCompass Static #{deviceScope.hardware.hasCompass} true, false DeviceManager.hasCompass()
hardware.hasFileAccess Static #{deviceScope.hardware.hasFileAccess} true, false DeviceManager.hasFileAccess()
hardware.hasLocalStorage Static #{deviceScope.hardware.hasLocalStorage} true, false DeviceManager.hasLocalStorage()
hardware.hasMediaPlayer Static #{deviceScope.hardware.hasMediaPlayer} true, false DeviceManager.hasMediaPlayer()
hardware.hasMediaRecorder Static #{deviceScope.hardware.hasMediaRecorder} true, false DeviceManager.hasMediaRecorder()
hardware.networkStatus Dynamic #{deviceScope.hardware.networkStatus} "wifi","2g","unknown" DeviceManager.getNetworkStatus()
hardware.screen.width Dynamic #{deviceScope.hardware.screen.width} 320, 480 DeviceManager.getScreenWidth()
hardware.screen.height Dynamic #{deviceScope.hardware.screen.height} 480, 320 DeviceManager.getScreenHeight()
hardware.availableWidth Dynamic #{deviceScope.hardware.availableWidth} <= 320, <= 480 DeviceManager.getAvailableScreenWidth()
hardware.availableHeight Dynamic #{deviceScope.hardware.availableHeight} <= 480, <= 320 DeviceManager.getAvailableScreenHeight()
hardware.screen.dpi Static #{deviceScope.hardware.screen.dpi} 160, 326 DeviceManager.getScreenDpi()
hardware.screen.diagonalSize Static #{deviceScope.hardware.screen.diagonalSize} 9.7, 6.78 DeviceManager.getScreenDiagonalSize()
hardware.screen.scaleFactor Static #{deviceScope.hardware.screen.scaleFactor} 1.0, 2.0 DeviceManager.getScreenScaleFactor()
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 12
PRODUCT DEMONSTRATION ACCESSING DEVICE PROPERTIES via EL Expression
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 13
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 14
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 15
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 16
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 17
PRODUCT DEMONSTRATION ACCESSING DEVICE PROPERTIES via a Java Bean
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 18
01 public class MyBean {
02
03 // Called via a button
04 public void actionSendSms(ActionEvent event) {
05 DeviceManager device = DeviceManagerFactory.getDeviceManager();
06
07 boolean hasCamera = device.hasCamera();
08 }
Device Properties API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 19
Accessing Device Properties
Service Data Control EL Access Programmatic
Device Properties Yes Yes
Send SMS Yes Yes
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 20
PRODUCT DEMONSTRATION SENDING SMS via the Data Control
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 21
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 22
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 23
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 24
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 25
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 26
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 27
PRODUCT DEMONSTRATION SENDING SMS via a Java Bean
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 28
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /**
04 * Display the operating system's default UI for sending a text
05 * message, and optionally pre-populate certain fields
06 *
07 * @param to - recipient list (comma-separated)
08 * @param body - text of message
09 */
10 public void sendSMS(java.lang.String to, java.lang.String body)
Send SMS API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 29
01 public class MyBean {
02
03 // Called via a button
04 public void actionSendSms(ActionEvent event) {
05 DeviceManager device = DeviceManagerFactory.getDeviceManager();
06
07 String to = "11112222,33334444";
08 String body = "A test SMS";
09
10 device.sendSms(to, body);
11 }
12 }
Send SMS API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 30
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 31
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 32
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 33
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 34
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 35
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 36
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 37
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 38
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 39
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 40
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 41
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 42
Accessing Device Properties
Service Data Control EL Access Programmatic
Device Properties Yes Yes
Send SMS Yes Yes
Send Email Yes Yes
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 43
PRODUCT DEMONSTRATION SENDING EMAIL via the Data Control
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 44
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 45
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 46
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 47
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 48
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 49
PRODUCT DEMONSTRATION SENDING EMAIL via a Java Bean
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 50
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Display the operating system's default UI for sending an e-mail, and
04 * optionally pre-populate certain fields.
05 *
06 * @param to - recipient list (comma-separated)
07 * @param cc - carbon copy recipient list (comma-separated)
08 * @param subject - subject line
09 * @param body - text of e-mail
10 * @param bcc - blind carbon copy recipient list (comma-separated)
11 * @param attachments - list of files to attach (comma-separated). Must be
12 * specified as absolute filenames;
13 * @param mimeTypes - list of MIME types, specified in the same order as
14 * the list of attachments.
15 */
16 public void sendEmail(java.lang.String to, java.lang.String cc,
17 java.lang.String subject, java.lang.String body,
18 java.lang.String bcc, java.lang.String attachments,
19 java.lang.String mimeTypes)
Send Email API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 51
01 public class MyBean {
02
03 // Called via a button
04 public void actionSendEmail(ActionEvent event) {
05 DeviceManager device = DeviceManagerFactory.getDeviceManager();
06
07 String to = "[email protected], [email protected]";
08 String cc = "[email protected]";
09 String subject = "A test email subject";
10 String body = "A test email body";
11
12 device.sendEmail(to, cc, subject, body, null, null, null);
13 }
14 }
Send Email API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 52
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 53
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 54
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 55
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 56
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 57
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 58
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 59
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 60
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 61
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 62
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 63
Accessing Device Properties
Service Data Control EL Access Programmatic
Device Properties Yes Yes
Send SMS Yes Yes
Send Email Yes Yes
Create Contact
Find Contacts
Update Contact
Remove Contact
Yes
Yes
Yes
Yes
Yes
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 64
Working with Contacts
Operations –
– Find Contacts
– Create Contact
– Update Contacts
– Remove Contact
Both update and remove operations use a Contact object as a
parameter
– retrieved from a findContact operation
ADF Mobile provides a contact related objects
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 65
PRODUCT DEMONSTRATION WORKING WITH CONTACTS via the Data Control
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 66
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 67
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 68
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 69
PRODUCT DEMONSTRATION WORKING WITH CONTACTS via a Java Bean
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 70
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Save a previously-created Contact to the device's address book
04 * Note that you can create a Contact by simply instantiating one
05 * and setting its properties, but in order to persist it, you
06 * must call createContact.
07 *
08 * @param contact - a previously-constructed Contact object
09 * @return - a Contact object. Note that you should always
10 * use the returned Contact object in subsequent
11 * operations, because this object will have the
12 * requisite primary key
13 */
14 public Contact createContact(Contact contact)
Create Contact API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 71
01 public class MyBean {
02
03 public void actionCreateContact(ActionEvent event) {
04 DeviceManager device = DeviceManagerFactory.getDeviceManager();
05
06 Contact contact = new Contact();
07 contactName contactName = new ContactName();
08 contactName.setFamilyName("Doe");
09 contactName.setGivenName("Joe");
10 contact.setName(contactName);
11 ContactField phoneNo = new ContactField();
12 phoneNo.setType("mobile");
13 phoneNo.setValue("650-000-1234");
14 ContactField[] phoneNos = new ContactField[] { phoneNo };
15 contact.setPhoneNumbers(phoneNos);
16
17 Contact newContact = device.createContact(contact);
18 }
Create Contact API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 72
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Enables retrieval of one or more Contact objects matching the criteria.
04 *
05 * @param contactFields - comma-delimited list of field names to match on,
06 * e.g. "id,displayName,name,nickname”.
07 * @param filter - search criteria. It is matched against all fields
08 * specified in contactFields
09 * @param multiple - return multiple contacts or first found
10 * @return - an array of Contact objects. Note that each
11 * Contact object will ONLY contain the fields you
12 * specified in the contactFields parameter; all
13 * others will be empty/null
14 */
15 public Contact[] findContacts(java.lang.String contactFields,
16 java.lang.String filter, boolean multiple)
Find Contacts API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 73
01 public class MyBean {
02
03 public void actionFindContacts(ActionEvent event) {
04 DeviceManager device = DeviceManagerFactory.getDeviceManager();
05 // This will return just one contact with only the ID field:
06 Contact[] foundContacts1 = device.findContacts("", "", false);
07 // This will return all contacts with only ID fields:
08 Contact[] foundContacts2 = device.findContacts("", "", true);
09 // This will return just one contact with all fields:
10 Contact[] foundContacts3 = device.findContacts("*", "", false);
11 // This will return all contacts with all fields:
12 Contact[] foundContacts4 = device.findContacts("*", "", true);
13
14 String fields = "name,phoneNumbers,emails,addresses";
15 String filter = "Smith";
16 Contact[] contacts = device.findContacts(fields, filter, true);
17 }
Find Contacts API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 74
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Update an existing Contact object. Note that you can modify a
04 * Contact via its various properties and methods, but in order to
05 * persist the changes, you must call updateContact.
06 *
07 * @param aContact – the modified Contact object to persist in the
08 * device's address book.
09 * @return - the modified Contact object.
10 */
11 public Contact updateContact(Contact aContact)
Update Contact API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 75
01 public class MyBean {
02
03 public void actionUpdateContact(ActionEvent event) {
04 DeviceManager device = DeviceManagerFactory.getDeviceManager();
05
06 Contact[] contacts = device.findContacts("name", "Smith", true);
07 // Assuming only 1 record returned
08 contacts[0].getPhoneNumbers()[0].setValue("650-111-1234");
09 contacts[0].getEmails()[0].setType("work");
10 contacts[0].getAddresses()[0].setPostalCode("94065");
11
12 Contact updatedContact = device.updateContact(contacts[0]);
13 }
14 }
Update Contact API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 76
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Remove a contact from the address book.
04 *
05 * @param aContact – the Contact object to remove.
06 */
07 public void removeContact(Contact aContact);
Remove Contact API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 77
01 public class MyBean {
02
03 public void actionRemoveContact(ActionEvent event) {
04 DeviceManager device = DeviceManagerFactory.getDeviceManager();
05
06 Contact[] contacts = device.findContacts("name", "Smith", true);
07 // Assuming only 1 record returned
08 device.removeContact(contacts[0]);
09 }
10 }
Remove Contact API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 78
Accessing Device Properties
Service Data Control EL Access Programmatic
Device Properties Yes Yes
Send SMS Yes Yes
Send Email Yes Yes
Create Contact
Find Contacts
Update Contact
Remove Contact
Yes
Yes
Yes
Yes
Yes
Get Picture Yes Yes
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 79
PRODUCT DEMONSTRATION ACCESSSING THE CAMERA via the Data Control
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 80
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 81
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 82
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 83
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 84
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 85
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 86
PRODUCT DEMONSTRATION ACCESSSING THE CAMERA via a Java Bean
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 87
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Provides access to the device's default camera application, which enables
04 * taking a picture or retrieving a previously-save image.
05 *
06 * @param quality – quality of save image. Range 0 to 100
07 * @param destinationType – Choose the format of the return value.
08 * - 0 – base64 encoded string – 1- URI to file:///
09 * @param sourceType - Where should the picture come from?
10 * - 0 – Library – 1 – Camera – 2 – Album
11 * @param allowEdit - Allow simple editing of image before selection
12 * @param encodingType - Encoding of saved imaged - 0 – JPG – 1 – PNG
13 * @param targetWidth - Width in pixels to scale image
14 * @param targetHeight - Height in pixels to scale image
15 * @returns - A String of either the base64 image or a file URK
16 */
17 public String getPicture(int quality, int destinationType, int sourceType,
18 boolean allowEdit, int encodingType,
19 int targetWidth, int targetHeight);
Get Picture API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 88
01 public class MyBean {
02
03 // Called via a button
04 public void actionGetPicture(ActionEvent event) {
05 DeviceManager device = DeviceManagerFactory.getDeviceManager();
06
07 String imageData =
08 device.getPicture(100,
09 DeviceManager.CAMERA_DESTINATIONTYPE_FILE_URL
10 DeviceManager.CAMERA_SOURCETYPE__PHOTOLIBRARY,
11 false,
12 DeviceManager.CAMERA_ENCODINGTYPE_JPEG,
13 0, 0);
14 }
Get Picture API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 89
Working With The Camera
Pay attention to picture quality
– File size impacts memore/network traffic
To return picture to the page:
– Set destinationType to 1 (file name)
– Drop Return of getPicture as Output Text
– Drop Image component onto page
– Set source to return input value (#{bindings.Return.inputValue})
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 90
Accessing Device Properties
Service Data Control EL Access Programmatic
Device Properties Yes Yes
Send SMS Yes Yes
Send Email Yes Yes
Create Contact
Find Contacts
Update Contact
Remove Contact
Yes
Yes
Yes
Yes
Yes
Get Picture Yes Yes
Start Location
Monitor Yes Yes
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 91
Working with Location Services
Acquire the device's current position
One instant in time, or on a periodic basis
Uses the startLocationMonitor operation
Use a geo-decoder to get address from coordinates
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 92
PRODUCT DEMONSTRATION USING THE GPS via the Data Control
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 93
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 94
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 95
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 96
PRODUCT DEMONSTRATION USING THE GPS via a Java Bean
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 97
01 public class oracle.adf.model.datacontrols.device.DeviceManager {
02
03 /** Register a callback to receive updates on the device's position
04 *
05 * @param updateInterval - how often to retrieve position(ms).
06 * @param enableHighAccuracy – receive best possible results at cost of
07 * increased power/computation expense.
08 * @param watchID - unique handle id that can be used to
09 * subsequently stop listening for updates.
10 * @param callback - an implementation of
11 * GeolocationCallback which can be invoked
12 * at updateInterval to deliver the
13 * device's location.
14 */
15 public java.lang.String startUpdatingPosition(
16 int updateInterval, boolean enableHighAccuracy,
17 java.lang.String watchID,GeolocationCallback callback)
Start Updating Position API
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 98
01 public class MyBean {
02
03 // Called via a button
04 public void actionGetPicture(ActionEvent event) {
05 DeviceManager device = DeviceManagerFactory.getDeviceManager();
06
07 String watchID = device.startUpdatingPosition(20000,
08 true, "MyGPSSubscriptionID",
09 new GeolocationCallback() {
10 public void locationUpdated(Location position) {
11 System.out.println("Location updated to: " + position);
12 }
13 });
14 device.clearWatchPosition(watchID);
15 }
16 }
Start Updating Position API Example
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 99
Summary
Accessing on device features is via an API wrapping PhoneGap
(Cordova)
– Refer to both the Oracle and 3rd party documentation
Dependent on the feature you can access it via EL expressions, the
data control or Java code
Some device features cannot be tested via the provided iOS
Simulator and Android emulator, only a real device will do
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 100