Android

Installation

The Pinn Android Library provides easy, secure and customizable authentication and biometric registration for your Android application. The Pinn Android Library is contained in single .aar (Android Archive) file:

  • lib-pinn-1.x.x.aar

This guide will guide you in integrating the Pinn library into your project both with regard to project settings and required code.

Prerequisites

  • An Android application with a minimum SDK version of Android 6.0 (API Level 23)
  • Android Studio

Download

Currently all downloads are done via private download links. Please contact sales@pinn.ai for access. Once accessed, unzipped content will live in ~/Downloads/Pinn-Android_v*

Configure

  1. Navigate to the folder previously unzipped to ~/Downloads/Pinn-Android_v*
  2. Add the lib-pinn-1.x.x.aar file to your project by adding it as a new Module. In Android studio, follow File > New > New Module
  3. Select “Import .JAR/.AAR Package” and follow the prompts to select the lib-pinn-1.x.x.aar that was previously unzipped. The .AAR will be imported as a subproject, feel free to name this subproject as it suits you.

    !

    Note

    We'll be referring to the subproject as lib-pinn. If you do not change the name when importing, you'll have to include the -.x.x.x version on subsequent steps.

  4. Next, include the lib-pinn subproject in your project’s settings.gradle file
    include ':lib-pinn'
                
  5. Finally add lib-pinn to your application level build.gradle file as a dependency. You'll also have to add an additional compileOption as seen below.
    android {
        compileOptions {
            sourceCompatibility 1.8
            targetCompatibility 1.8
        }
    }
    dependencies {
        implementation project(':lib-pinn')
    }
                
  6. Sync your project with the gradle files.

Getting an App Publishable Key

In order to configure the SDK in the next step your will need to obtain a publishable_key that represents your Android application. This key is safe to embed in source code and allows for the Pinn services to identify your application. Using your account's secret key simply call our API with a name and optional description of your application.

For more details look at the API reference documentation on Apps.

Request

POST https://pinnapis.com/v1/apps/android
Authorization: Bearer sk_UB8hITybDSwMBVSEBGYV8ZqYAaabHS5e

{
    "name": "My Android App",
    "description": "An optional description about my app"
}
        

Response

{
    "app_id": "app_1h8hISXxbhwsjN12GZ8vY6Kr",
    "app_type": "android",
    "created_at": 1547736791,
    "description": "An optional description about my app",
    "name": "My Android App",
    "object": "app",
    "publishable_key": "pk_1h8hISXxbhwt4AWcp2XCe4pXJhPNPpz9",
    "updated_at": 1547736791
}
        

Notice the publishable_key value returning in the JSON response. You may now directly embed this value into your Android app.

App Level Configuration

In your main activity, initialize your client with your publishable key.

Initialize the API

import co.pinn.authx.Pinn;

@Override
public void onCreate() {
    Pinn.initialize("yourPublishableKey");
}
        

Declaring and Requesting Required Permissions

Add the following to your AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
        

From an Activity

if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.CAMERA)
        != PackageManager.PERMISSION_GRANTED) {
    // Permission is not granted
    requestCameraPermissions();
}

private static final CAMERA_PERMISSION_REQ_CODE = 1234;

void requestCameraPermissions() {
    ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.CAMERA},
                    CAMERA_PERMISSION_REQ_CODE);
}

// Handle permission request result
@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case CAMERA_PERMISSION_REQ_CODE:
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // permission granted! proceed to use Pinn
            } else {
                // permission denied
            }
        break;
    }
}
        

See the following guide for more details.

Using the Pinn Library

Your principal interaction point with the Pinn Library is via the Pinn class defined in Pinn.java. It is the main gateway to Pinn's functionality and all of the examples here utilize the functions listed there.

!

Note

The Palm and QR scanning functionality of the Pinn framework require that your application be built against a device. As such the framework will not run on an app compiled for the simulator.

At this point you should be able to build and run your app to confirm you're configured correctly.

Next

First steps with our mobile SDKs is enrolling. See our user guide for more details.

?

Questions?

We are here to help! Contact us with any development related questions at dev@pinn.ai and we'll reach back in a timely manner.