We will describe the steps to integrate the FuturaeKit SDK into your Android project. We are going to assume that you are using Android Studio for your development.
### <a id="get-futuraekit-sdk-for-android" />Get FuturaeKit SDK for Android
Git clone this repository inside your project, in order to have full access to the FuturaeKit SDK project.
![][clone]
### <a id="add-sdk-to-project" />Add SDK to Project
If you are using Gradle, add the following to your `build.gradle` file:
```
compile project(':futuraekit-java')
```
also make sure to modify your `settings.gradle` file:
```
include ':futuraekit-java'
```
### <a id="add-permissions" />Add permissions
Please add the following permissions, which the FuturaeKit SDK needs, if they are not already present in your AndroidManifest.xml file:
If you are using Proguard, add these lines to your Proguard file:
```
TBD
```
### <a id="basic-setup" />Basic setup
We recommend using an android [Application][android_application] class to initialize the SDK. If you already have one in your app already, follow these steps:
1. In your `Application` class find or create the `onCreate` method and add the following code to initialize the FuturaeKit SDK:
```java
importcom.futurae.sdk.FuturaeClient;
publicclassAppMainextendsApplication{
// overrides
@Override
publicfinalvoidonCreate(){
super.onCreate();
FuturaeClient.launch(this);
}
}
```
![][application_config]
2. In your `res/values` folder make sure to create a file `futurae.xml` with the following contents:
**Note**: Initializing the FuturaeKit SDK like this is `very important`. Replace `{FuturaeApiKey}` with your Futurae API key, and `{GoogleApiProjectNumber}` with the project number of the Google API you have set up for the GCM (see the [GCM Token Registration](#gcm-token-registration) section for more information).
### <a id="build-your-app" />Build your app
Build and run your app. If the build succeeds, you should carefully read the SDK logs in the console.
## <a id="features" />Features
### <a id="callbacks" />Callbacks
The SDK methods that perform API calls use callbacks as the feedback mechanism. These calls expect an object of the `FuturaeCallback` interface as an argument:
```java
publicinterfaceFuturaeCallback{
voidsuccess();
voidfailure(Throwablethrowable);
}
```
### <a id="uri-schemes" />URI Schemes
The SDK is able to handle URI scheme calls, for URIs that start with the `futurae://` prefix, which are used to either **enroll** or **authenticate** a user. To enable this behaviour in your app, you must add the following intent filter in your manifest, inside the activity that will handle the intent:
Once the activity has been set up to handle the URI scheme call intents, get the intent data in the `onCreate()` method of your activity, which contains the URI that should be passed in the SDK, using the `handleUri()` method:
Your app must be set up to receive GCM push notifications from our server. You can choose to receive and handle these notifications yourself, or alternatively you can use the existing infrastructure provided in the SDK. You can find more information on how to setup GCM push notifications for your app in the [Google Cloud Messaging Developer Guide](https://developers.google.com/cloud-messaging/android/client).
In order to be able to receive GCM notifications, you need to specify the following components inside the application section of your Manifest:
The `FTRRegistrationIntentService` is responsible for registering the app's GCM token to the Futurae server. This is important for the server to be able to issue GCM notifications for your app. The provided service handles this, however if you need to, you can write your own or extend the existing one. The call that registers the GCM token to the Futurae server is `registerPushToken()`, and it is necessary every time the GCM token is generated or is changed by GCM.
For example, once the app receives a new GCM token (e.g. via an `InstanceIdListenerService`), the token needs to be obtained and registered to the Futurae server using the following code:
The `FTRGcmListenerService` receives GCM push notifications and handles them, according to the actions dictated by the Futurae server. You can use or extend the service provided by the SDK, or write your own. There are two distinct push notification types issued by the Futurae server: **Aprove** or **Unenroll**.
In case you want to process and handle the GCM notifications without using `FTRGcmListenerService`, you must use the following code in order to process and handle the notifications sent by the Futurae server, inside the implementation of your `GcmListenerService`:
Once a Futurae GCM notification has been handled, the SDK will notify the host app using **local broadcasts**. The app should register a broadcast receiver for these intents and react accordingly. There are three distinct Intents that the notification handlers might send in a local broadcast:
*`INTENT_GENERIC_NOTIFICATION_ERROR`: Indicates that an error was encountered during the processing or handling of a GCM notification.
*`INTENT_APPROVE_AUTH_MESSAGE`: Indicates that a Push Notification Authentication has been initiated.
*`INTENT_ACCOUNT_UNENROLL_MESSAGE`: Indicates that a user account has been logged out remotely.
The following example shows how to register for these intents:
```java
IntentFilterintentFilter=newIntentFilter();
intentFilter.addAction(Shared.INTENT_GENERIC_NOTIFICATION_ERROR);// General notification error intent
// Handle approve notification (e.g. show approve view)
break;
caseShared.INTENT_GENERIC_NOTIFICATION_ERROR:
// Handle GCM notification error
break;
}
}
},intentFilter);
```
### <a id="enroll-user" />Enroll User
To enroll a user, you must call the `enroll()` method, using a valid code obtained by scanning an enrolment QR Code. For example, you can use a QR Code Reader Activity to scan a code and obtain the result:
Typically this should happen either when the user removes the account manually from the app, or when a user has been logged out remotely by the server. In the former case, calling the `logout()` method is enough, as it notifies the server of the logout and deletes the account from the SDK too. In the latter case, the server will send a GCM notification to the app, and the default handler of the notification will delete the account from the SDK as well. In this case, the notification handler will also send a local broadcast to the app (see `INTENT_ACCOUNT_UNENROLL_MESSAGE`[above](#local-intents), so that the app can also perform any further action required (e.g. refresh the list of active accounts in an account view).
To authenticate (or reject) a user session, depending on the authentication factor, you can use the following methods: **QR Code Factor**, or **Push Notification Factor**.
#### <a id="qrcode-auth" />QR Code Factor
To authenticate with the QR Code Factor, scan the QR Code provided by the server and pass its contents to the following method:
When a Push Notification Factor session is initiated on the server side, the server will send a push notification to the app, where the user should approve or reject the authentication session. The notification is received and handled by the SDK, which in turn will send a local broadcast (see `INTENT_APPROVE_AUTH_MESSAGE`[above](#local-intents)), so that the app can perform any required actions. For example, the app might want to display a prompt to the user so that they can approve or reject the session.
The intent contains an object that describes the authentication session as an extra. This object contains the User ID and the Session ID, which are required for sending the authentication outcome to the server:
The user might choose to reject the authentication session. Additionally, in case the session has not been initiated by the user, they might also choose to report a fraudulent authentication attempt back to the server. In this case, use the following method:
```java
booleanreportFraud=false;// Set to true to report a fraudulent attempt
The TOTP Factor can be used for offline authentication, as there is no requirement for an internet connection in the app. To get the current TOTP generated by the SDK for a specific user account, call the following method:
Stringpasscode=totp.passcode;// The TOTP that the user should use to authenticate
intremainingSeconds=totp.remainingSecs;// The remaining seconds of validity of this TOTP
```
As seen in this example, the `nextTotp()` method returns an object that contains the TOTP itself, but also the remaining seconds that this TOTP will be still valid for. After this time, a new TOTP must be obtained by the SDK.