Petnow LogoPetnow
Android SDK

Integration Guide

Step-by-step guide to integrate the Petnow Android SDK.


Overview

The Petnow SDK for Android provides developers with a simple way to integrate pet biometric detection and identification capabilities into their Android applications. This guide will walk you through the process of integrating and using the Petnow SDK's two main modules:

  • ApiClient Module: Handles API communication with Petnow's cloud services.
  • UI Module: Provides camera functionality for pet detection and biometric capture.

Prerequisites

  • Minimum SDK version: 28 (Android 9.0)
  • Java version: 17
  • Kotlin 1.8 or newer
  • A valid Petnow API key

Installation

Step 1: Install the AWS CLI

Install the AWS CLI using the following link: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Step 2: Configure the AWS CLI

Configure the AWS CLI with your AWS credentials: https://docs.aws.amazon.com/cli/latest/userguide/cli-authentication-user.html

Note: Set the default region name to ap-northeast-1.

Step 3: Add the Petnow Maven Repository

Add the Petnow Maven repository to your project-level build.gradle file

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            name "CodeArtifact"
            url System.getenv("CODEARTIFACT_URL") ?: "YOUR_REPOSITORY_URL"
            credentials {
                username "aws"
                password System.getenv("CODEARTIFACT_AUTH_TOKEN") ?: "YOUR_AUTH_TOKEN"
            }
        }
    }
}

Step 4: Configure AndroidManifest.xml

Add the following permissions and configurations to your app's AndroidManifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

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

    <application
        ..
        android:largeHeap="true"
        ...
    >
        ...
    </application>

</manifest>

The INTERNET permission is required for API communication, and largeHeap="true" is necessary for optimal performance during image processing and detection operations.

Step 5: Add Dependencies

Add the following dependencies to your app's build.gradle.kts file:

dependencies {
    // Petnow SDK modules
    implementation("io.petnow:api-client:$latestVersion")
    implementation("io.petnow:ui:$latestVersion")
}

SDK Initialization

Step 1: Initialize the API Client

Initialize the Petnow API client in your application's onCreate() method:

class YourApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Initialize the Petnow API client
        PetnowApiClient.init(
            key = "YOUR_API_KEY",
            isDebugMode = BuildConfig.DEBUG,
            onSuccess = { result ->
                Log.d("PetnowSDK", "API client initialized successfully")
            },
            onError = { exception ->
                Log.e("PetnowSDK", "Failed to initialize API client", exception)
            }
        )
    }
}

Note about isDebugMode parameter:

This parameter determines which Petnow server environment your app will connect to:

  • true: Connects to the Stage (development) environment - use this during development and testing
  • false: Connects to the Production environment - use this for release builds in the market

We recommend setting this to BuildConfig.DEBUG so that your development builds automatically use the Stage environment, while release builds use the Production environment.

You can also manually control this setting based on your own environment variables or build flavors if needed.

Configure Detection Mode

Important: You must configure the detection mode before navigating to any fragment that extends PetnowCameraFragment:

// Configure for dog nose detection for pet registration
PetnowApiClient.configureDetectionMode(
    purpose = DetectionPurpose.PET_PROFILE_REGISTRATION,
    species = PetSpecies.DOG
)

// Or configure for cat face detection for pet verification
PetnowApiClient.configureDetectionMode(
    purpose = DetectionPurpose.PET_VERIFICATION,
    species = PetSpecies.CAT
)

Sample Implementation

Here's a complete sample implementation of a pet registration flow:

  1. Initialize SDK in Application class
  2. Create a custom camera fragment
  3. Handle detection results
  4. Register the pet with the server

Please refer to the provided ClientCameraFragment example for a complete implementation.

Support

If you encounter any issues or have questions about the SDK, please contact Petnow support at support@petnow.io.

Next

Proceed to the UI Guide to embed components.