Next, we can quickly embed the SDK in your Android app to store card details, authorize payments, and capture a transaction.

Add the SDK

The Android SDK is available as a Maven bundle on Jitpack. In Gradle, this can be set up as follows.

repositories {
  mavenCentral()
  maven { url "https://jitpack.io" }
}

dependencies {
  implementation 'com.github.gr4vy:gr4vy-android:v1.4.0'
}

Set up the app

Next, add the following meta information to your app’s manifest.

<meta-data android:name="gr4vy-id" android:value="[ID]" />
<meta-data android:name="gr4vy-environment" android:value="[ENVIRONMENT]" />

Replace [ID] with the ID of your instance and [ENVIRONMENT] with either sandbox or production.

Additionally, ensure you have internet access added to the permissions in your manifest.

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

Prepare the SDK

Next, add the following to the top of your activity where you want to enable the payment sheet.

private lateinit var gr4vySDK: Gr4vySDK

Then, initialize the SDK within the onCreate() method of your activity.

gr4vySDK = Gr4vySDK(activityResultRegistry, this, this)

Next, register the observer as follows.

lifecycle.addObserver(gr4vySDK)

Finally, implement the Gr4vyResultHandler interface on the activity and implement the required methods.

class MainActivity : ComponentActivity(), Gr4vyResultHandler