Integrating FastLink 3 for Android
FastLink can be integrated into your Android application through WebView. Prerequisites to integrate FastLink is Android 7.0+. FastLink 3 currently supports the US locale only. If the FastLink application is launched from a locale other than the US, a technical error will be given.
Integration Steps
Follow the steps to integrate FastLink into an Android application. The code samples use the Java
language. FastLink can equally be loaded from the corresponding Kotlin
code.
Step 1: Generate an Access Token
FastLink uses the client credentials authentication mechanism. You must pass a valid accessToken
to authenticate your invocation of the FastLink application. Generate the access token by following the instructions provided in the Getting Started with Client Credentials page.
Step 2: Create the WebView
Instance
You can either programmatically create the WebView
instance or add it through the Layout Editor.
import android.webkit.WebView;
public class WebViewActivity extends AppCompatActivity {
public WebView webview;
public static Uri.Builder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
.....
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(webViewClient);
.....
}
WebViewClient webViewClient = new WebViewClient() {
//You can override the WebViewClient methods here
}
}
Step 3: Create the Request Object
Once the WebView
instance is created, you have to create the request object.
try {
builder = new Uri.Builder()
.appendQueryParameter("accessToken", "Bearer {{ACCESS_TOKEN}}")
.appendQueryParameter("app", "10003600")
.appendQueryParameter("extraParams", URLEncoder.encode( "...", "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String query = builder.build().getQuery();
Step 4: Load the Request Object in the WebView
Instance
Once the request object is ready, load this it in the WebView
instance. This will render the FastLink inside WebView
.
webview.postUrl(<FASTLINK_URL>, query.getBytes());
Passing Additional Params to FastLink
While creating the request object, additional params like deep-linking flow
attributes, addOns
, callback details, etc., can be passed as query parameters. Following is a sample code snippet for the add
deep-link flow.
try {
builder = new Uri.Builder()
.appendQueryParameter("accessToken", "Bearer {{ACCESS_TOKEN}}")
.appendQueryParameter("extraParams", URLEncoder.encode( "flow=add&providerId=16441", "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
For more details, refer to the Additional Params section in FastLink 3 Advanced Integration.
Handling Open Banking Sites
The intentUrl
attribute is used get the control back to the native app from an external application.
Pass intentURL
as part of extraParams
try {
builder = new Uri.Builder()
.appendQueryParameter("accessToken", "Bearer {{ACCESS_TOKEN}}")
.appendQueryParameter("extraParams", URLEncoder.encode( "intentUrl=protocol://domainname", "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
When the user selects an Open Banking site, FastLink will send a post message with the site's OAuth URL which needs to be opened in a native browser.
Post Message - OPEN_EXTERNAL_URL
{
"type": "OPEN_EXTERNAL_URL",
"data": {
"url": "<OAUTH URL>"
}
}
Once the user logs in, authorizes consent, and completes the flow, the callback URL will be the intent URL which will be redirected to the intentUrl
.
The native app should listen to this intentUrl
by which control comes back to the native app.
Handling Callback
<activity
android:name="com.yodlee.fastlink.InAppBrowserActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize|adjustPan">
<intent-filter>
<data
android:host="domainname"
android:scheme="protocol" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Handling Events from FastLink
To communicate the events from FastLink, your application has to listen for the JSInterfaceHandler
delegate method. Note that the name should be YWebViewHandler
as FastLink will check for this name and send the events.
class JSInterfaceHandler {
Context mContext;
JSInterfaceHandler(Context c) {
mContext = c;
}
@JavascriptInterface
public void postMessage(final String data) {
//Data will contain the all the communication messages sent from FastLink
Log.d("FL:MESSAGE", data);
}
}
Add the JSInterfaceHandler
config to the WebView
instance.
webview.addJavascriptInterface(new JSInterfaceHandler(this), "YWebViewHandler");
External URL
The FastLink application shares the account addition status to your application using the POST_MESSAGE
events.
{
"type": "POST_MESSAGE",
"data": {
//Post Message data
}
}