Integrating FastLink 4 for Android
FastLink can be integrated into your Android application through WebView. Prerequisites to integrate FastLink is Android 7.0+.
Integration Steps
Follow the steps to integrate FastLink into an Android application. The code samples here 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("extraParams", URLEncoder.encode( "configName=<config-name-from-config-tool>", "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, callback details, etc., can be passed as query parameters along with the mandatory configName
parameter. 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( "configName=<config-name-from-config-tool>&flow=add&providerId=16441", "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
For more details, refer to the Additional Params section in FastLink 4 Advanced Integration.
Handling Open Banking Sites
The intentUrl
attribute is used get the control back to the native app from an external application. Example, native browser.
Passing intentUrl
as part of extraParams
try {
builder = new Uri.Builder()
.appendQueryParameter("accessToken", "Bearer {{ACCESS_TOKEN}}")
.appendQueryParameter("extraParams", URLEncoder.encode( "configName=<config-name-from-config-tool>&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, authorize consent, and completes the flow, use intentUrl
as callback URL.
Native app should listen to this intentUrl
by which the control comes back to the native app.
Handling Callback
Entries in AndroidManifest.xml.
<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 with 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 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");
Post Message Events
The FastLink application shares the account addition status to your application using the POST_MESSAGE
events.
{
"type": "POST_MESSAGE",
"data": {
//Post Message data
}
}
External URL
You must open the URL in the Chrome Custom Tabs or in the default mobile browser. You MUST NOT open the external URL within the Andriod WebView
. Doing so will result in blocked requests from many data providers due to security vulnerabilities.
{
"type": "OPEN_EXTERNAL_URL",
"data": {
"url": "<External URL>"
}
}