4 Using an Android Application on the SQLite Mobile Client

The following sections uses the simple_sync_android project to describe the steps to include the SQLite Mobile Client within your signed application.

Note:

This chapter assumes that you know how to use Eclipse to build an Android project and how to appropriately develop and sign an Android application.

4.1 Prerequisites

The following are the prerequisites for enabling synchronization for a SQLite application:

  1. Install Eclipse IDE with the ADT plug-in, as detailed at the following site:

    http://developer.android.com/sdk/eclipse-adt.html#installing
    
  2. Install the latest Android SDK, as detailed at the following site:

    http://developer.android.com/sdk/index.html
    
  3. Install the Mobile Development Kit.

4.2 Import the Oracle Database Mobile Server Android Project into Eclipse

Import the Oracle Database Mobile Server simple_sync_android sample Android project into your Eclipse Workspace.

The following steps show how to import the mobile server sample Android project.

  1. In Eclipse, with your Workspace open, select File->Import and choose Existing Projects into Workspace. Click Next.

    Figure 4-1 Import Existing Projects into Eclipse Workspace

    Import project into eclipse workspace
    Description of "Figure 4-1 Import Existing Projects into Eclipse Workspace"

  2. Set the root directory to point to the Android project within the Oracle Database Mobile Server MDK. Enable the Select Root Directory button and browse for the simple_sync_android project, which is located in the following directory:

    <MDK_ROOT>\Mobile\Sdk\samples\Sync\android\simple_sync_android
    

    where the <MDK_ROOT> is replaced with the full path where the Oracle Database Mobile Server MDK is installed.

    Figure 4-2 demonstrates setting the root directory. After which, all projects in the specified root directory are displayed in the Projects window.

    Figure 4-2 Select Root Directory for Eclipse Project

    Set root directory
    Description of "Figure 4-2 Select Root Directory for Eclipse Project"

  3. Select the simple_sync_android project and click Finish. The simple_sync_android project is now imported into your Eclipse Workspace.

4.3 Build Oracle Database Mobile Server Android Project

The following details how to build your Android project using the Oracle Database Mobile Server simple_sync_android sample project.

  1. Set required environment variables. The project references Oracle Database Mobile Server synchronization classes, which are located within the osync_android.jar library file. Set the MOBILE_SYNC_ANDROID_LIB environment variable to point to osync_android.jar file with the following steps:

    1. Highlight the simple_sync_android project in the Project Explorer window, as shown in Figure 4-3.

      Figure 4-3 Project Explorer window

      Project explorer window
      Description of "Figure 4-3 Project Explorer window"

    2. Select 'Alt Enter' to display the Project Properties window.

    3. As shown in Figure 4-4, select the Java Build Path in the left pane. Then, select the Libraries tab in the Build Path window. Select MOBILE_SYNC_ANDROID_LIB to configure the location of the JAR file. The MOBILE_SYNC_ANDROID_LIB variable provides the library directory where the osync_android.jar file is located, which is required to build your project. Click Edit.

      Figure 4-4 Properties for simple_sync_android Project

      Add new variable
      Description of "Figure 4-4 Properties for simple_sync_android Project"

    4. In the "Edit Variable Entry" dialog, click the Variable button.

      Figure 4-5 Edit the MOBILE_SYNC_ANDROID_LIB Variable

      Configure a new variable
      Description of "Figure 4-5 Edit the MOBILE_SYNC_ANDROID_LIB Variable"

    5. Click Edit.

      Figure 4-6 Edit Path Variable

      Add new path variable
      Description of "Figure 4-6 Edit Path Variable"

    6. Enter <MDK_ROOT>/Mobile/Sdk/android/lib/osync_android.jar in the Path field.

      Figure 4-7 Add Path to the MOBILE_SYNC_ANDROID_LIB Environment Variable

      Create environment variable
      Description of "Figure 4-7 Add Path to the MOBILE_SYNC_ANDROID_LIB Environment Variable"

    7. When finished, click OK.

    8. In the "Classpath Variables Changed" dialog, select Yes to rebuild the project.

      Figure 4-8 Classpath Variables Changed

      Create environment variable
      Description of "Figure 4-8 Classpath Variables Changed"

  2. Build the simple_sync_android project to link in the osync_android.jar file with the Oracle Database Mobile Server synchronization libraries.

  3. Execute and debug the simple_sync_android project with the Android emulator.

    1. Right click on the simple_sync_android project.

    2. Click Run As and select Android Application.

      Figure 4-9 Executing the Android Application

      Executing the Android application
      Description of "Figure 4-9 Executing the Android Application"

      The Android emulator is started, where you can execute the sample as the Mobile Sync application.

      Figure 4-10 Test Project with Android Emulator

      Android emulator
      Description of "Figure 4-10 Test Project with Android Emulator"

  4. When you execute the Mobile Sync application, synchronization is initiated. Enter your user name, password and mobile server URL in the Sync UI, as shown in Figure 4-11. Click Sync to start the synchronization.

    Figure 4-11 Synchronization UI

    Synchronization UI on Android
    Description of "Figure 4-11 Synchronization UI"

  5. Examine the MainAct.java code. The sample consists of the UI layout code that is located in the res\layout subdirectory. The main application Java class file is MainAct.java, which contains all of the logic for initializing synchronization structures and invoking the synchronization methods. You can examine this file for more details on the sequence of calls for the synchronization APIs.