Android

Add the Mati button to your Android app.

Android Demo App

You can go to GitHub to download the Mati Android Java demo app.

Requirements & size

Android: v5.0 (API v21) or higher.

Kotlin: 1.4 or higher.

SDK size: ~2.5MB

Install the Mati Android SDK

To install the Mati Android SDK using Gradle, you will need to do the following:

  • Ensure that your top-level build.gradle references to the following repository:
    java maven { url 'https://repo1.maven.org/maven2' }

  • Enable Java 1.8 source compatibility.

        ```java
        android {
            compileOptions {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
            }
        }
        ```
    
  • Add the following line to the list of gradle dependencies for your version of the Mati Android SDK:

        ```java
        implementation ('com.getmati:mati-sdk: <your Mati SDK version number>'){
            exclude group: 'org.json', module: 'json'
        }
        ```
    
        For example, if you are using the Mati Android SDK version 3.11.1, you would include the following line:
    
        ```java
        implementation ('com.getmati:mati-sdk:3.11.1'){
            exclude group: 'org.json', module: 'json'
        }
        ```
    

Then sync your project with the gradle files.

Note The following dependencies will be automatically installed with Mati library:

`androidx.appcompat:appcompat:1.3.1`
`androidx.recyclerview:recyclerview:1.2.1`
`androidx.constraintlayout:constraintlayout:2.0.4`
`com.google.android.material:material:1.4.0`
`androidx.lifecycle:lifecycle-process:2.2.0`
`androidx.lifecycle:lifecycle-common-java8:2.2.0`
`com.google.code.gson:gson:2.8.5`
`org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.31`
`androidx.fragment:fragment-ktx:1.3.0`
`androidx.core:core-ktx:1.3.2`
`io.socket:socket.io-client:1.0.0`
`androidx.camera:camera-core:1.0.1`
`androidx.camera:camera-camera2:1.0.1`
`androidx.camera:camera-lifecycle:1.0.1`
`androidx.camera:camera-view:1.0.0-alpha27`
`org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0`
`androidx.lifecycle:lifecycle-runtime-ktx:2.3.1`
`androidx.navigation:navigation-fragment-ktx:2.3.3`
`androidx.navigation:navigation-ui-ktx:2.3.3`
`androidx.navigation:navigation-dynamic-features-fragment:2.3.3`

Usage

  1. Add the MatiButton to your layout

    <com.getmati.mati_sdk.MatiButton
        android:id="@+id/matiKYCButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        app:color="@color/matiButtonColor"
        app:textColor="@color/matiButtonTextColor"
        app:text="YOUR CUSTOM TEXT" />
    
  2. Call setParams with the following arguments to authorize the app and start verification:

    ParameterTypeRequired
    activity@NonNull ActivityRequired
    CLIENT_ID@NonNull StringRequired
    FLOW_ID@Nullable StringRequired
    BUTTON_TITLE@NonNull StringOptional
    METADATA
    Note Go to the Metadata section
    to learn more about using metadata
    @Nullable MetadataOptional

    Java

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.activity_main);
    
        ...
    
        this.<MatiButton>findViewById(R.id.matiKYCButton).setParams(
            this,
            "CLIENT_ID",
            "FLOW_ID",
            METADATA);
    }
    

    Kotlin

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        setContentView(R.layout.activity_main);
    
        ...
    
        findViewById<MatiButton>(R.id.matiKYCButton).setParams(
            this,
            "CLIENT_ID",
            "FLOW_ID",
            METADATA)
    }
    
  3. Listen for KYCActivity results

    Java

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == MatiSdk.REQUEST_CODE) {
            if(resultCode == RESULT_OK) {
                Toast.makeText( this,"SUCCESS!!!", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText( this,"CANCELLED!!!", Toast.LENGTH_LONG).show();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
    

    Kotlin

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == MatiSdk.REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                Toast.makeText(this, "SUCCESS!!!", Toast.LENGTH_LONG).show()
            } else {
                Toast.makeText(this, "CANCELLED!!!", Toast.LENGTH_LONG).show()
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data)
        }
    }
    
  4. Check for your activity

    Java

    public class YourActivity extends AppCompatActivity implements MatiCallback {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_main);
    
            this.<MatiButton>findViewById(R.id.matiKYCButton).setParams(
            this,
                "CLIENT_ID",
                "FLOW_ID",
                new Metadata.Builder()
                    .with("key_1", "value1")
                    .with("key2", 2)
                    .build());
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(requestCode == MatiSdk.REQUEST_CODE) {
                if(resultCode == RESULT_OK) {
                    Toast.makeText( this,"SUCCESS!!!", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText( this,"CANCELLED!!!", Toast.LENGTH_LONG).show();
                }
            } else {
                super.onActivityResult(requestCode, resultCode, data);
            }
        }
    }
    

    Kotlin

    class SecondActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_second)
    
            findViewById<MatiButton>(R.id.matiKYCButton).setParams(
            this,
                "CLIENT_ID",
                "FLOW_ID",
                Metadata.Builder()
                    .with("key_1", "value1")
                    .with("key2", 2)
                    .build())
        }
    
        override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
            if (requestCode == MatiSdk.REQUEST_CODE) {
                if (resultCode == RESULT_OK) {
                    Toast.makeText(this, "SUCCESS!!!", Toast.LENGTH_LONG).show()
                } else {
                    Toast.makeText(this, "CANCELLED!!!", Toast.LENGTH_LONG).show()
                }
            } else {
                super.onActivityResult(requestCode, resultCode, data)
            }
        }
    }
    

Metadata Usage

You can use metadata to set specific parameters, including setting a selected language and hiding the language selection to make it permanent.

key: fixedLanguage

value: locale code of language

Example: Set the Language Code for Spain

To set the language code for Spain to Spanish, we would set the fixedLanguage parameter to es"

Java

new Metadata.Builder()
                .with("fixedLanguage", "es")
                .build();

Kotlin

Metadata.Builder()
                .with("fixedLanguage", "es")
                .build()

If you don't use MatiButton, you can set the buttons' primary color and text color with metadata:

key: buttonColor
value: parsed color-int value

key: buttonTextColor
value: parsed color-int value

Example: Set button color red(#FF0000) and text color white(#FFFFFF)

Java

new Metadata.Builder()
                .with("buttonColor", Color.parseColor("#FF0000"))
            .with("buttonTextColor", Color.parseColor("#FFFFFF"))
                .build();

Kotlin

Metadata.Builder()
                .with("buttonColor", Color.parseColor("#FF0000"))
            .with("buttonTextColor", Color.parseColor("#FFFFFF"))
                .build()

If you use MatiButton, this values will be ignored and MatiButton's colors will be applied to all the screens.


Did this page help you?