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.
This tutorial covers the following topics:
- Creating a MobileFirst native API
- The wlclient.properties file
- Creating and configuring an Android native application
- Tutorials to follow next
Creating a MobileFirst native API
- In the terminal with the CLI installed, create a new MobileFirst project using:
$ mfp create HelloWorldNative.
- Go to the newly created project directory:
$ cd HelloWorldNative/.
- Add a new Android native API using
$ mfp add api AndroidHelloWorld -e android.
- Build and deploy the application using
$ mfp bd. This action is required for MobileFirst Server to recognize the application if it attempts to connect.
- 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.
Note: This action is required for MobileFirst Server to recognize the application when a request reaches the server.
The MobileFirst native API contains the following components:
wlclient.propertiesfile contains the connectivity settings that a native Android application uses.
worklight-android.jarfile is the MobileFirst API library.
push.pngfile is used for displaying an image for an incoming push notification.
proguard-project.txtfile contains configuration settings for using Android ProGuard with Android Native API.
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
- You use the
application-descriptor.xmlfile to define application metadata and to configure security settings that MobileFirst Server enforces.
The wlclient.properties file
wlclient.properties file holds server configuration properties and is user-editable.
wlServerProtocol– The communication protocol to MobileFirst Server, which can be either
wlServerHost– The hostname of MobileFirst Server.
wlServerPort– The port of MobileFirst Server.
wlServerContext– The context root path of the application on MobileFirst Server.
wlAppId– The application ID as defined in the
wlAppVersion– The application version.
wlEnvironment– The target environment of the native application.
wlUid– The property used by MTWW, the text workbench, to identify this as a MobileFirst application.
wlPlatformVersion– The MobileFirst SDK version.
languagePreferences– The list of preferred locales.
GcmSenderId– This property defines the Google Cloud Message (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 generated NativeAPI folder to the new native Android application, in the
- Copy the
wlclient.propertiesfile from 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, see the topic about developing native applications for Android, in the user documentation.
Tutorials to follow next
Now that your application contains the Native API library, you can follow the tutorials in the Native Android Development section to learn more about authentication and security, server-side development, advanced client-side development, notifications and more.▲