This article explains how to use example code properly for Android SDK
Configuration in Admin Portal
Before implementing the example code, you need to configure several things such as generate Trusted Certificate, Add API Endpoints, and Create API Group.
Generate New Trusted Certificate
First, Login to the Admin portal. Go to Settings, then Click Configurations. You can see in the right section there are 3 menu, click Trusted Certificate.
Then click Generate Certificate. Fill the certificate name as you want, and do not forget to fill the PassPhrase Certificate. If you finish, click Generate on right below.
After that, the new certificate already generated. Click Download Client Certificate to save the Certificate in your local directory.
Add API Endpoint
Set your API Endpoint in admin portal. Go to Settings then Click API Protection.
To create new API Endpoint, click New API Endpoint in right above. As example, create echo API from Postman echo-server for sample API that to be used on Example code. And fill the form as follows:
- Name: echo
- Endpoint Address/FQDN/Hostname: postman-echo.com
- Protocol: HTTPS
- Other settings: using default settings (no changed)
If finished fill the form, click Save.
Then create another simple web API Endpoint for testing. You need to add New API Endpoint and fill the form like this:
- Name: simple-web
- Endpoint Address/FQDN/Hostname: 192.168.0.1
- Protocol: HTTP (or HTTPS. It's depends on your environment)
- Other settings: using default settings (no changed)
Click Save if you finished.
Create New Default API Group
As a summary for those API Endpoint that already created, you need create an API group. Go to Settings, click API Protection then go to API group on left bar.
Click New API Group on right above. Fill the form with the instruction below:
- API Group Code: default
- Description: Default Group Description (or fill as you want)
- Trusted Certificate: cert-1
- API Application (Main): echo, simple-web
After that, click Save.
Download Source Code of the Example Code
Get the example code from GitHub by clone the repository.
https://github.com/iij-safous/safous-waap-sdk-android-example
After clone the example code repository, open the project in Android Studio.
Download SDK from Admin Portal.
Get the WAAP SDK for Android from admin portal. Login to admin portal, then go to Settings then click SDK on left bar. You will see the list of SDK version that WAAP release.
Click Download button in right side of the list for get the SDK into your local directory.
Put Certificate and SDK into Example Code project.
So in the first you already download the certificate and SDK then put on local directory. Now for certificate, move it to raw directory in project.
<project>/app/src/main/res/raw
For SDK, put it on libs directory in project.
<project>/app/libs
Setup Environment and update URL
As a reminder, consider to take a look at the Admin Portal for setup the API endpoints. There are 2 parts that needs to be create. First you have to create 3 Endpoints for setup the registration environments. There are Authentication, Registration, and Verification. It may look like the image below.
Second, you need to create another 2 Endpoints for testing. There are Simple and Echo API. If it is done, It may look like the image below.
Now open the project from Android Studio. Then open Setup Activity file and change into this configuration. As example, you can see from url from GitHub below. Make sure the Authentication, Register, and Verification endpoints that you already created exactly same with the configuration.
static final String appId = "default";
static final String urlRegister = "https://waap-register.example-waap.waap.safous.com";
static final String urlAuth = "https://waap-auth.example-waap.waap.safous.com";
static final String urlVerification = "https://waap-client-verification.example-waap.waap.safous.com";
static final String password = "PASSPHRASE_FOR_CLIENT_CERTIFICATE";
Next, update the URL for Transaction modules in Safous WAAP. Open Example Transaction Activity files, then set the URL that you already generated from admin portal. For more you can see the detail from GitHub link below. Check the Simple and Echo API that you created in Admin Portal already correct with the configuration.
ExampleTransactionActivity L20-L21
public String urlBasicApi = "https://simple-web.example-waap.waap.safous.com/"
public String urlEchoApi = "https://echo.example-waap.waap.safous.com/"
Build and Run the Example Code Project
Open your Android Studio with Example Code project in it. Click Run on taskbar or Click Ctrl+R from your keyboard. There are 3 classes you can run such as ExampleSetup, ExampleRegistration, and ExampleTransaction. All 3 classes have a different purposes as you can see the detail below.
Class | Description |
ExampleSetupActivity | This is use as setup and declaration parameter that determine which environment you used for your codebase. |
ExampleRegistrationActivity | This is an example of registration, using registerDevice and verifyDevice method |
ExampleTransactionActivity | This is an example of transaction, using transaction method and simple-web API endpoint, Echo server API Endpoint, and Terminate method. |