+

Search Tips | Advanced Search

For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


Some initial code for accessing the server

A simple startup process for Android-based applications for accessing the server is described here.


The main activity

Before we can access the server resources, we must register the app on the server. For more information, see Register Android applications to MobileFirst Server.

You must also deploy an adapter. For more information about using adapters, see Client access to adapters.

This example is based on the sample code created in Set up Android Studio projects with Gradle.


Import the MFP client API and create an instance

Some imports are required to run this example:

The WLClient is used throughout the application to connect to the server.

The resource request calls the getBankBalance adapter and writes messages to the log for success or failure.

Replace the entire MainActivity with the code that follows.


Accessing the server without deploying an adapter

To test the server connectivity without deploying an adapter, request an access token. If no security checks were added to our app, and the server can be accessed, the token can be obtained. The token request is sent without a scope:

The entire MainActivity consists of creating the WLClient and requesting the access token:

The MyObtainAuthorizationHeaderListener listener returns success or error messages.

The error or success message is printed to the Android monitor pane in Android Studio.

After your app connects successfully to the server, we can continue to develop your app.

Parent topic: Develop native applications in Android Studio