Creating the Android project to work with Sybase Unwired platform in Eclipse or Sybase Unwired Workspace

Creating the Android Project

Create a new Android project in Sybase Unwired WorkSpace. Add library resources to the project and set other application properties.
Prerequisites
To help create your project—and in a subsequent topic, build the user interface—download the SUP101 Android Object API (2.2 SP02) example project from the SAP Community Network (SCN) Web site at http://scn.sap.com/docs/DOC-8803.
Task
  1. Start Sybase Unwired WorkSpace.
  2. In Sybase Unwired WorkSpace Preferences, set the Android SDK location.
  3. Select File > New > Project.
  4. Select Android > Android Application Project, then Next.
    Depending on the Android version you are using, the information you provide in the next several steps may be in one or two screens.
  5. In the New Android Application window, use these values and click Next.
    • Application Name – enter SUP101Android.
    • Project Name – enter SUP101Android.
    • Package Name – enter com.mycorp.sup101.android.app.
    • Minimum Required SDK – accept the default.
    • Target SDK – select the Android SDK used for the tutorial.
    • Compile With – select the Android SDK used for the tutorial.
    • Theme – accept the default.

    Android Tutorial New Android Application Window
  6. In the New Android Application window, use these values and click Next.
    • Select Create custom launcher icon, Create activity, and Create Project in Workspace.
    • Unselect Mark this project as a library and Add project to working sets.

    Android Tutorial Configure Project Window
  7. In the Configure Launcher Icon window, accept the default settings and click Next.

    Android Tutorial Configure Launcher Icon Window
  8. In the Create Activity window select Create Activity, then select BlankActivity, and click Next.

    Android Tutorial Create Activity Window
  9. In the New Blank Activity window, use these values and click Finish.
    • Activity Name – enter SUP101SampleActivity.
    • Layout Name – enter main.
    • Navigation Type – accept the default of None.

    Android Tutorial New Blank Activity Window
The left pane of the Workspace Navigator should list the SUP101Android project. In the src folder, a default Sample Activity class was automatically generated when you created the project.
Tip: To correct a misspelled package name, right-click the package and select Refactor > Rename to change the name and update all references.

Adding Compiler and Library Resources

Add compiler and library resources to the Android project.
  1. Add a compiler resource to the root directory of the project:
    1. In Windows Explorer, browse to SUP_HOME\MobileSDK22\ObjectAPI\Android and copy the armeabi folder and these JAR files: AfariaSLL.jar, ClientLib.jar, sup-client.jar, and UltraLiteJNI12.jar.
    2. In Workspace Navigator, expand SUP101Android, select the libs folder, and paste the armeabi folder and JAR files into it.
  2. Add library resources to the project:
    1. In Workspace Navigator, right-click the SUP101Android project, click Properties, and select Java Build Path.
    2. Click the Libraries tab and select Add JARs.
    3. In the JAR Selection window, expand the SUP101Android\libs folder and select AfariaSSL.jar, ClientLib.jar, sup-client.jar, and UltraLiteJNI12.jar.
    4. Close the windows.
     

Copying Unwired Platform Files to Sample Project

Copy the object API code you generated using the Generate Code wizard for Android.
  1. In Workspace Navigator, go to the SUP101 project and copy the com folder in \Generated Code\Android\src\.
  2. Go to the SUP101Android project and paste the com folder in to the src directory. Select Yes to All to copy over existing folders.

Creating the User Interface

Copy the Java code files, which provide the functionality and layout of the user interface, from the SUP101 Android Project example project archive to the SUP101Android project.
  1. In Windows Explorer, browse to the directory where you saved the SUP101 Android Project example project.
  2. Copy these Java files: CustomerListAdapter.java, DetailActivity.java, and SUP101SampleActivity.java.
  3. In Workspace Navigator, go to SUP101Android and expand \src\com\mycorp\sup101\android\app, then paste the copied Java files, copying over any existing files.
  4. Modify the host IP address in the SUP101SampleActivity.java file to point to the Unwired Server.
    1. In Workspace Navigator, expand the SUP101Android project.
    2. Under the \src\com\mycorp\sup101\android\app folder, double-click the SUP101SampleActivity.java file.
    3. Modify the host IP address, and verify the username and password are valid.
  5. Browse to the directory where you saved the ZIP file.
  6. From the ZIP file, copy the sample layout XML files: customer.xml, detail.xml, and main.xml.
  7. In the SUP101Android project folder, go to the res\layout directory and paste the copied XML files, copying over any existing files.
    The SUP101Android project directory should look like this:
    Android Tutorial SUP101Android Sample Directory

Adding User Permissions and a Class to the Android Manifest File

Add user permissions to the Android project. Also add a Detail Activity class to the AndroidManifest.xml file. This declaration launches a customer detail screen where you can make changes when you test the application.
  1. If needed, open the Android manifest file.
  2. Select the AndroidManifest.xml tab.
  3. Replace the code with the source code from the AndroidManifest.xml file you downloaded from the SAP Community Network (SCN) Web site, also provided below:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.mycorp.sup101.android.app"
     android:versionCode="1"
     android:versionName="1.0" >
    
        <uses-sdk
         android:minSdkVersion="8"
         android:targetSdkVersion="15" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    
        <application
         android:allowBackup="true"
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
         android:theme="@style/AppTheme" >
         <activity
          android:name=".SUP101SampleActivity" >
          <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
         </activity>
         <activity android:name=".DetailActivity"
          android:label="@string/app_name">
          <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
         </activity>
        </application>
    </manifest> 
    
    
  4. Select File > Save.

Creating a Launch Configuration for the Project

Create a new launch configuration for the SUP101Android project. The configuration specifies how the application launches, and defines the target Android platform.
Prerequisites
In the Sybase Unwired WorkSpace, use the AVD Manager to add a new target Android Virtual Device (AVD).
Task
  1. In Workspace Navigator, right-click the SUP101Android project, and select Run As > Run Configurations.
  2. Right-click Android Application and select New.
  3. In the Name field, enter SUP101.
  4. In the Android tab, click Browse and select SUP101Android. Click OK.
  5. In the Launch Action area, select Launch Default Activity.

    Android Tutorial Run As Configurations Window
  6. In the Target tab, select a deployment target. For example, select Automatically pick compatible device, then specify an AVD for deployment. Accept all other default settings.

    Android Tutorial Configuration Target Tab
  7. Click Apply, then Close.

Testing the Device Application on the Android Emulator

Run the SUP101Android application on the Android emulator, and change customer information to update the interface.
  1. In WorkSpace Navigator, right-click SUP101Android and select Run As > Android Application.

    Android Tutorial SUP101 Android project Run As Android Application
                                Menu

    Note: It may take several minutes for the Android emulator's home screen to appear.
    The application activation (on boarding) image indicates that the application is registering data from Unwired Server.
    Android Tutorial SUP101 Android Project Onboarding Data
                                Window
    During initialization, the system enables the operation to target change notifications using:
    SynchronizationGroup sg=SUP101DB.getSynchronizationGroup("default"); 
    sg.setEnableSIS(true);
    sg.save();
                            
    When the data finishes synchronizing, the device application shows the SUP101Android application with a list of customer data in a ListView control. You can scroll through the customer list to see more data and to make changes. The data loads from the database on demand.
    Note: The Android application illustrates a device application with a small buffer (30 customers). In commercial applications, based on the amount of user data, you can use a large buffer (1,000 customers).
    When the application queries the customer list, it uses an SUP101DB.executeQuery() API to get only columns that are needed, such as (fname, lname...), instead of the entire customer object; this results in better performance.

    Android Tutorial SUP101 Android Project Customer List

  2. Select the customer to update.

    Android Tutorial SUP101 Android Project Highlighted Customer List
                            Screen
  3. In the customer detail screen, change the first name of the customer and click Submit.

    Android Tutorial SUP101 Android Project Customer Detail Screen
    The Submit button is mapped to the synchronize operation using SUP101DB.beginSynchronize. The synchronization occurs in the background, so the user interface is unaffected.
    Any back-end changes initiate notifications from the server. The device application uses a ChangeLog API to query those managed items and update the user interface if needed.
    GenericList<ChangeLog> changeLogs=SUP101DB.getChangeLogs(query);

    Android Tutorial SUP101 Android Project Customer Updated Screen
  4. Close the emulator to stop the SUP101Android application.
 

Comments

  1. From where should I get the following files?

    CustomerListAdapter.java, DetailActivity.java, and SUP101SampleActivity.java

    They are not present in http://scn.sap.com/docs/DOC-8803 as mentioned in this article.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to draw an overlay on a SurfaceView used by Camera on Android?

Create EditText with dropdown in android

Android TCP Connection Chat application