Part 3: Integrating with Device Features
In addition to the features you have already seen, you can use ADF Mobile to integrate with features that are built in to your device. For example, you can integrate with the device's camera, contacts, email, SMS, GPS, and son on. You will see in this section of the tutorial how to interact with the camera and email client.

Step 1: Add Camera Interaction

In this section, you add a button to the EmpList page that integrates with the camera of the device and navigates to the TakePicture page. On the TakePicture page, you add a button for taking another picture and a button to return to the EmpList page. You also add an image that shows the picture you just took.

  1. Open EmpTaskFlow.xml. (HINT: Double-click EmpsTaskFlow.xml in the Application Navigator.)

    alt text
  2. Double-click EmpList to open it in the editor.

    alt text
  3. Drag a Button component from the Component Palette to the Panel Item in the Structure pane.

    alt text

    alt text
  4. Set the Text of the button to Take a Picture and set the Action to takePicture.

    alt text

    alt text
  5. Now you start working on the TakePicture page. Open the TakePicture page in the editor. (HINT: Double-click TakePicture.amx in either the EmpsTaskFlow or the Application Navigator.)

    alt text
  6. Look for the outputText component under the header facet and set the value to Take a Picture.

    alt text
  7. Expand the Data Controls palette to show Device Features.

    alt text
  8. Expand getPicture(int,int,int,boolean,int,int,int). Notice the parameters that the getPicture method requires. The getPicture method allows the caller to set parameters on the method which control various aspects of the device. For example the method call can set the quality, height, and width of the results.

    alt text
  9. Drag getPicture(int,int,int,boolean,int,int,int) to the Panel Page in the Structure pane and drop it as an ADF Mobile Button.

    alt text

    alt text
  10. In the Edit Action Binding dialog box, enter the following values for the parameters and click OK to create the button.

    Name Value
    quality 50
    destinationType 1
    sourceType 1
    allowEdit true
    encodingType 1
    targetWidth 200
    targetHeight 200
    alt text
  11. The page and code should look something like this:

    alt text

    In the next few steps, you to add an output text component bound to the return of the getPicture method. As you would suspect, the return from the camera is a picture not text. We are adding the output text component for the purpose of creating the binding to the return of the method. After you add the output text component, you will add an image component and copy the binding to be the source of the image component. After you copy the binding, you will delete the text field.

  12. From the Data Controls palette, drag the String return from the getPicture method to the Panel Page in the Structure pane and drop it as an ADF Mobile Output Text.

    alt text
  13. From the ADF Mobile AMX General Controls, drag an Image component from the component palette to the Panel Page in the Structure pane.

    alt text
  14. In the code editor, copy the binding code from the outputText component, using Ctrl + C.

    alt text
  15. Select the image component and in the Property Inspector, paste the binding code into the Source property (use Ctrl + V).

    alt text
  16. Select the outputText field in either the Code Editor or the Structure pane and delete it.

    alt text
  17. Select the Button component in the Facet - primary node of the Panel Page.

    alt text
  18. Use the Property Inspector to set the Text to Back and the Action to __back.

    alt text
  19. Just as you did before, deploy the application. (HINT: From the Application menu in JDeveloper, select Deploy > Android2 to Android emulator.)
    Also make sure the emulator is already up and running.

    alt text
  20. Click the Applications button on the main page, and then click the Employees application.

    alt text
  21. When the application opens, click Take a Picture. This will open the Camera feature on the emulator.

    alt text
  22. The camera emulator has a green box that moves around on a checkered background. Click the shutter button (the blue circle in the middle of the footer) to take a picture.
    If you get a message about the Camera has stopped working, check the AVD setup to make sure the Back Camera is Emulated.

    alt text
  23. Click the checkmark, on the right side of the footer to accept the image.

  24. The device camera closes and returns to your application. Your application then displays the picture in the image component that you added to the TakePicture page.

    alt text

    You have successfully used ADF Mobile to interact with a standard device feature. In the next section you add a Java program that interacts with the email feature of the device.

Step 2: Add Java Code to Send an Email

In this section, you expand the application by adding Java code to send email programmatically. Rather than dragging a device data control to a page, you access the device feature from Java code.

  1. In JDeveloper, open the TakePicture page in the editor.

    alt text
  2. Drag a Button from the Component palette to the PanelPage. You use this button to call the method to send an email.

    alt text
  3. Set the Text property to Send Email.

    alt text
  4. Rather than using the Device Features data control from the Data Controls palette, we will create a JavaBean to call the device feature. To create the JavaBean and method, click the down arrow to the right of the Action Listener property and select Edit.

    alt text
  5. In the Edit Property: Action Listener dialog box, click the New button next to the Managed Bean list.

    alt text
  6. In the Create Managed Bean dialog box, set the following property values and then click OK.

    Name Value
    Bean Name: backingPic
    Class Name BackingPic
    Scope view
    alt text
  7. Click the New button next to the Method list to create a new method.

    alt text
  8. Set the Method Name to sendEmail, and then click OK.

    alt text
  9. Click OK to create the Java class and the method.

    alt text
  10. Double-click BackingPic.java in the Application Navigator to open it in the editor. (HINT: Expand Application Sources > mycomp.mobile.)

    alt text
  11. Find the sendMail(ActionEvent actionEvent) method and type the code DeviceManagerFactory inside the method. JDeveloper prompts you with a suggested import for the DeviceManagerFactory. Press Alt+Enter to add the import statement for oracle.adf.model.datacontrols.device.DeviceManagerFactory.

    alt text
  12. Type a period (.) at the end of DeviceManagerFactory and JDeveloper will propose a list of available methods from the class. Click getDeviceManager() and press return to add method call to your code.

    alt text

    alt text
  13. Click the getDeviceManager() method and press Ctrl+Alt+V to open the Introduce Variable dialog box. This dialog box proposes a variable and a type to add to this method. Click OK to accept the defaults.

    alt text

    alt text
  14. On a new line just below the deviceManager declaration, enter deviceManager.s. JDeveloper will propose a list of available methods. Choose sendMail(String,String,String,String,String,String,String) to add the method call to your code.

    alt text

    alt text
  15. Notice the names of the parameters that appear in the Data Controls palette under the sendMail method. Using the list of parameters as a guide, set the values in the method call to the following:

    Argument Value
    arg 0 (To) "Jeff @oracle.com"
    arg 1 (cc) ""
    arg 2 (subject) "An Email"
    arg 3 ((body) "Hello from me."
    arg 4 (bcc) ""
    arg 5 (attachments) ""
    arg 6 (mimeTypes) ""
    alt text
  16. Save your work.

  17. Just as you did before, deploy the application to the emulator. (HINT: Select Application > Deploy.)

    alt text
  18. When the deployment is complete, click the Applications button on the emulator, and then click the Employees application.

    alt text
  19. Click the Take a Picture button.

    alt text
  20. In the Camera feature, click the shutter button, and then click the checkmark icon to accept the picture.

    alt text
  21. On the next page, which is the TakePicture page, click Send Email.

    alt text
  22. The emulator does not have an email application configured by default, so it returns an error message when it tries to send the email. If you deploy the application to a device, the application uses the installed client. If there are multiple clients installed, the application prompts you to select an email client.

    alt text

In this tutorial, you created an ADF Mobile application and deployed to a mobile device or emulator. The application includes a basic form, a call to a web service and interaction with device features like the camera and an email client.


Bookmark Print Expand all | Hide all
Back to top
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.