Chapter 1. Native Android
API Documentation
- RHMAP Client API - documentation for all RHMAP Client APIs
- RHMAP Android SDK Reference - generated Javadoc documentation of classes and methods of the RHMAP Android SDK
1.1. Gradle
Gradle is a Java-based dependency management and build tool used for Android app development. It is used to distribute and integrate the RHMAP Native Android SDK with your app project.
1.1.1. Installing and Setting Up Gradle
Gradle requires Java JDK or JRE version 7 or higher. To check the version of Java you are currently using, execute the following command:
java -version
Gradle uses the JDK version specified in your PATH environmental variable. You can also set the JAVA_HOME environmental variable to point to the installation directory of the desired JDK version.
It is recommended that you use Gradle version 2.4 or higher
To install Gradle, follow the installation instructions and setup instructions on the Gradle website.
Alternatively, to install Gradle using the SDK manager tool, follow the section with instructions on installing Gradle using SDKMAN on the Gradle website.
1.2. Maven
Apache Maven is a project management and build automation tool for maintaining and distributing Java code. It is distributed under the Apache License, version 2.0. In an RHMAP context, is used to distribute the RHMAP Native Android SDK.
Maven 3.3 requires JDK 1.7 or later to execute. To check the version of Java you are currently using, execute the following command:
java -version
Maven uses the JDK version specified in your PATH environmental variable. You can also set the JAVA_HOME environmental variable to point to the installation directory of the desired JDK version.
You can download the latest version of Maven from the Maven developers' website.
See the Maven documentation for detailed instructions on how to install and configure Maven.
1.3. Getting Started
This SDK allows the user to use RHMAP APIs with native Android apps up to Android M (version 6.0, API level 23).
The RHMAP Android SDK is an open source project hosted in the FeedHenry Android SDK repository on Github. Feel free to fork it and contribute.
Before using the SDK, make sure you have the Android SDK or the Android Studio installed. You can download both from the Android Developer portal.
1.3.1. New App
Download the sample app to get started with a new native Android application which has the RHMAP SDK already included.
1.3.2. Existing App
Declare the following dependency in your build.gradle file:
compile 'com.feedhenry:fh-android-sdk:3.2.0'
Add this dependency to the app’s build.gradle file, not the project’s build.gradle file.
If you are not using Gradle, you can manually download the SDK in a JAR along with its dependencies. For more details, see the Usage section in the README file of the SDK’s Github repository.
If you use Maven to manage dependencies for your project, declare the fh-android-sdk as a dependency by adding the following code to the pom.xml file:
<dependencies> <dependency> <groupId>com.feedhenry</groupId> <artifactId>fh-android-sdk</artifactId> <version>3.2.0</version> </dependency> </dependencies>
1.3.3. RHMAP Android Permission Setup
The SDK requires the INTERNET permission. If not already added, add the permission to the AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET"/>
1.3.4. RHMAP Server Connection Setup
Define the properties which allow the app to communicate with RHMAP servers. Create a new file in the assets folder called fhconfig.properties. Add the following contents and replace the references, including the brackets, with the values from your project:
host = <RHMAP Core host> projectid = <Project ID> connectiontag = <Connection tag> appid = <Client App ID> appkey = <Client App API key>
This data is not considered security sensitive data. For more on app security such as User Authentication, see $fh.auth Client API.
An example of a configured fhconfig.properties file:
host = https://cldapps.testsite.com projectid = 0BiqQ5g8kfnUw8d1fn9NnAeR connectiontag = 0.0.2 appid = 0BiqQAqVu9quH6BIrlH_LT9c appkey = bfb20ee69d29add08e974eff89b9a571bacb7959
Additional properties you might encounter when working with RHMAP:
PUSH_SERVER_URL - <The hostname of the MBaaS target you will be targeting> PUSH_SENDER_ID - <Firebase Sender ID> PUSH_VARIANT- <UPS VARIANT> PUSH_SECRET - <UPS SECRET>
See Projects - Connections for more information on connections between Client Apps and Cloud Apps.
1.3.5. Initialization
Before invoking any cloud requests from the RHMAP SDK, initialisation is required:
FH.init(this, new FHActCallback() {
public void success(FHResponse pRes) {
// Init okay, free to use FHActRequest
}
public void fail(FHResponse pRes) {
// Init failed
Log.e("FHInit", pRes.getErrorMessage(), pRes.getError());
}
});1.4. Compatibility
If the app targets Android M (API Level 23), use a version 3.x or higher of the RHMAP Android SDK, ideally the latest version. The 3.x version of the SDK was introduced primarily because of a significant change in the Android SDK - the Apache HTTP Client. Apache HTTP Client (org.apache.http package) is no longer distributed with the Android SDK as of Android M. The RHMAP SDK now uses cz.msebera.android:httpclient as an HTTP client instead.
Upgrading an existing app to target Android M will also require an update to the app so it will use the new HTTP client. If Gradle is not being used, use the HTTP client’s JAR files which are distributed with the RHMAP SDK and are available in the deps folder of the repository.
For information on compatibility with Android N (API Level 24), see Android N.
1.5. Android N
Android N allows you to use certain Java 8 language features, such as lambda expressions. A lambda expression enhances the readability of code and also allows you to express instances of single-method classes more compactly. This contrasts with Anonymous classes which can be cumbersome. For more info, please refer to the lambda expression tutorial : https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html.
Within the context of RHMAP, lambda expressions have an impact on apps that use Jack and Java 8, specifically around the consumption of a lambda expression by the RHMAP APIs. With Java 8, a lambda expression can be passed into a method that consumes an Anonymous Inner class and it is likely that Lambda Expressions will impact DefaultCallbacks as shown in the following code:
@FunctionalInterface
public interface DefaultCallback extends FHActCallback {
default void fail(FHResponse pResponse) {
Log.e("DefaultCallback", pResponse.getErrorMessage());
};
@Override
void success(FHResponse pResponse);
}The following code snippet illustrates the use of a Lambda Expression within an RHMAP context:
@Override
protected void onStart() {
super.onStart();
FH.init(this, (DefaultCallback)(ignore) - > {
findViewById(R.id.check_online).setVisibility(View.VISIBLE);findViewById(R.id.check_online).setOnClickListener(view - > Toast.makeText(getBaseContext(), FH.isOnline() ? "Is online" : "Is not online", Toast.LENGTH_LONG).show());
}
);
}1.5.1. Migrating Apps to Android N
To migrate your app to Android N:
- Make sure your code is working before migrating.
-
Update the fh-android-sdk dependency from
3.1.0to3.3.0in your package management software. -
Update the build tools and target APIs in the
AndroidManifestandbuild.gradlefiles to API level 24. - Build your app locally and validate that everything is working.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.