Creating your first native Android MobileFirst application
To serve a native Android application, MobileFirst Server must be aware of it. For this purpose, IBM MobileFirst Platform Foundation provides a Native API library, which contains a set of APIs and configuration files.
This tutorial explains how to generate the Android Native API and how to integrate it with a native Android application. These steps are necessary so that you can use it later on to achieve tasks such as connecting to MobileFirst Server, invoking adapter procedures, implementing authentication methods, and so on.
Prerequisite: Developers must be proficient with using Google's developer tools.
Creating a MobileFirst Native API
- In MobileFirst Studio, create a MobileFirst project and add a MobileFirst Native API.
- In the New MobileFirst Native API dialog, enter your application name and select Android for the Environment field.
- Right-click the generated NativeAPI folder (located in
your-projects/apps/your-nativeapi-app-name) and select Run As > Deploy Native API.
This action is required for MobileFirst Server to recognize the application when a request reaches the server.
The MobileFirst native API contains several components:
wlclient.propertiescontains the connectivity settings that a native Android application uses.
worklight-android.jaris the MobileFirst API library.
push.pngare for Google push notification services.
JSONStorefolder is for optional JSONStore support in native applications.
x86folders are for optional Application Authenticity Protection in native applications.
- As with any MobileFirst project, you create the server configuration by modifying the files that are in the server\conf folder.
- You use the
application-descriptor.xmlfile to define application metadata and to configure security settings that MobileFirst Server enforces.
wlclient.properties file holds server configuration properties and is user-editable.
wlServerProtocol– The communication protocol to MobileFirst Server, which can be either http or https.
wlServerHost– The hostname of MobileFirst Server.
wlServerPort– The port of MobileFirst Server.
wlServerContext–The context root path of the application on the MobileFirst Server.
wlAppId– The application ID as defined in the application-descriptor.xml file.
wlAppVersion– The application version.
wlEnvironment– The target environment of the native application.
wlUid– The property used by MTWW to identify this as a MobileFirst application.
wlPlatformVersion– The MobileFirst Studio version.
languagePreferences– List of preferred locales.
GcmSenderId– This property defines the GCM Sender ID to be used for push notifications. By default, this property is commented out.
Creating and configuring an Android native application
- Create a native Android application or use an existing one.
- Copy the
android-async-http.jarfiles from the WorklightAPI folder to the new native Android application, in the
- Copy the file
wlclient.propertiesfrom the MobileFirst native API folder to the new native Android application, in the
- Add the following permissions to the
- Add the MobileFirst UI activity:
For more information, review the "Developing native applications for Android" user documentation topicAfter the application is run in Eclipse, the final result is a native application that contains the MobileFirst API library. The provided Studio project contains a MobileFirst Studio project with the generated NativeAPI folder. The provided Native project contains an Android application already setup with the MobileFirst NativeAPI.