Synaps
Search…
Android
Synaps integrates its workflow easily on Android devices without extra packages or SDK. Thanks to Intent and Deep Links. Here is a guided tour of how integrating Synaps on native Android.

1. Create a Synaps app

To start, you need to create an app. After logged in to your Synaps Manager interface, just click on New app. Go to integration tab and copy your Synaps API Key

2. Integrate Synaps Sessions with your Private API

As you are dealing with a mobile app, no sensitive information should appear on it. You should store no credentials, passwords, API Keys directly in your mobile codebase as it can easily be accessed by anyone.
The most common way to deal with sensitive information is to call your Private API and set a authorization mechanism using access token for instance. This mechanism will lets you call the API with a time-based token and will keep every sensitive data in your backend.
Synaps API Key is a sensitive information. This key will lets you generate new verification sessions and access sessions information.
Synaps Session ID is not a sensitive information. This Session ID has been built for front-end. It can be exposed publicly without any problem because it exposes no user information. It has been designed to only upload information.
As you are designing an Android app and as it is considered as a front-end (publicly accessible), your goal is to call your private API that will generates a Synaps Session ID for you.

3. Create a simple android app

    1.
    Open Android Studio and click "Start a new Android Studio Project"
2. Select "Empty Activity"
3. Name your app and click "Finish"
4. App Created!
The following screen is the basic app directory with base code.
5. Add verify button
Go to your activity_main.xml located at app/src/main/res/layout/activity_main.xml, add a button and set the ID as verify_btn
6. Create an event listener for your button
1
package com.example.synapssample
2
3
import android.content.Intent
4
import android.net.Uri
5
import androidx.appcompat.app.AppCompatActivity
6
import android.os.Bundle
7
import android.widget.Button
8
9
class MainActivity : AppCompatActivity() {
10
override fun onCreate(savedInstanceState: Bundle?) {
11
super.onCreate(savedInstanceState)
12
setContentView(R.layout.activity_main)
13
14
findViewById<Button>(R.id.verify_btn).setOnClickListener {
15
/* Code Here */
16
}
17
}
18
19
}
Copied!
7. Build Synaps Session URL
You can see in the following code block that the Synaps Session Link is static. Let's see how to build it dynamically.
1
package com.example.synapssample
2
3
import android.content.Intent
4
import android.net.Uri
5
import androidx.appcompat.app.AppCompatActivity
6
import android.os.Bundle
7
import android.util.Log
8
import android.widget.Button
9
import java.net.URLEncoder
10
11
class MainActivity : AppCompatActivity() {
12
override fun onCreate(savedInstanceState: Bundle?) {
13
super.onCreate(savedInstanceState)
14
setContentView(R.layout.activity_main)
15
16
// Deeplink set in your AndroidManifest.xml to allow Synaps to redirect your user once onboarded
17
val deepLink = "com.synaps.sample://back"
18
19
// Encode URL to avoid conflict with Session URL
20
val deepLinkEncoded = URLEncoder.encode(deepLink, "utf-8")
21
22
// Session Id previously initialized using your private API
23
val sessionId = "aca98307-9ace-b7b5-7afe-9e8b2f8f"
24
25
// Primary Color
26
val primaryColor = "00707F"
27
28
// Secondary Color
29
val secondaryColor = "FFFFFF"
30
31
// Default lang (available: en, fr)
32
val lang = "en"
33
34
findViewById<Button>(R.id.verify_btn).setOnClickListener {
35
// Init Intent
36
val openURL = Intent(android.content.Intent.ACTION_VIEW)
37
38
// Build Session URL
39
openURL.data = Uri.parse("https://verify.synaps.io/?session_id=$sessionId&service=individual&lang=$lang&deeplink_redirection=$deepLinkEncoded&mobile=ios&primary_color=$primaryColor&secondary_color=$secondaryColor")
40
41
// Launch Activity
42
startActivity(openURL)
43
}
44
}
45
46
}
Copied!
deepLink is the scheme that you previously added in your AndroidManifest.xml to authorized web browser to be redirected to your app using this scheme. In other words, you authorized anyone to go to your app simply by typing in safari com.synaps.verify://back. Once the user will click "back to app", Synaps will trigger this deepLink and you will be able to handle the callback.
Add custom scheme to your AndroidManifest.xml
Open your AndroidManifest.xml and add the following code
1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
package="com.example.synapssample">
4
5
<application
6
android:allowBackup="true"
7
android:icon="@mipmap/ic_launcher"
8
android:label="@string/app_name"
9
android:roundIcon="@mipmap/ic_launcher_round"
10
android:supportsRtl="true"
11
android:theme="@style/AppTheme">
12
<activity android:name=".MainActivity">
13
<intent-filter>
14
<action android:name="android.intent.action.MAIN" />
15
16
<category android:name="android.intent.category.LAUNCHER" />
17
</intent-filter>
18
19
<intent-filter>
20
<action android:name="android.intent.action.VIEW" />
21
<category android:name="android.intent.category.DEFAULT" />
22
<category android:name="android.intent.category.BROWSABLE" />
23
<data android:scheme="com.synaps.sample"
24
android:host="back" />
25
</intent-filter>
26
27
</activity>
28
</application>
29
30
</manifest>
Copied!
Change com.synaps.sample with your own android:scheme and back with your own android:host
Handling callback
The above chunk of the code is triggered when the user come back to your app. At this moment, you have to handle your business logic. The most common way is to call your Private API to pull data from Synaps about the current authenticated user.
1
// Handle Callback
2
val action: String? = intent?.action
3
val data: Uri? = intent?.data
4
5
if (data.toString() == deepLink) {
6
// Call to Private API
7
Toast.makeText(getApplicationContext(), "Pull data from Private API", Toast.LENGTH_SHORT).show();
8
9
}
Copied!
The Synaps Session Link will remains approximately always the same only session_id and service parameters will change for Android integration.
1
https://verify.synaps.io/?session_id={SESSION_ID}&service={SESSION_SERVICE}&deeplink_redirection={DEEPLINK_REDIRECTION}&mobile=ios
Copied!
If you have any technical question, don't hesitate to reach [email protected]
Last modified 2mo ago