Ramp Android SDK is a library that allows you to easily integrate Ramp into your Android app and communicate with it.
In this tutorial, we'll install the SDK via Gradle and initialize it with configuration data. We'll also go over implementing callbacks for events sent by Ramp.
Installing the Gradle Plugin
To install the Ramp Android SDK, add its repository in your root
build.gradle at the end of repositories:
Add the dependency in your
Initializing the SDK
Go to an
Activity or a
Fragment in your directory where you want to start a transaction with Ramp.
Add the following import statements to the top of the file:
After that, you need to initialize the SDK with your activity context.
Filling the configuration object with your data
Ramp widget allows you to provide some useful parameters before displaying it. Most of the parameters are optional. You can set options such as user wallet address, desired cryptocurrency and crypto amount, etc. In order to do so, we need to add those parameters to a
Config object provided by SDK.
You can find the description of all available parameters in our documentation.
Create a callback object
RampCallback to handle transaction events that you can react to in your app.
Methods you can get by implementing this object:
onPurchaseCreated(purchase: Purchase, purchaseViewToken: String, apiUrl: String)is called when a purchase is created, and returns a
Purchaseobject, containing all its parameters. All fields of are described in the documentation here.
onPurchaseFailed()is called when Ramp fails in any aspect. You will see the reason of failure on the screen.
onWidgetClose()is called when Ramp finishes the flow and can be closed, or user closed it manually.
Starting the widget
That's it, now you just need to run the
startTransaction(activity: Activity, config: Config, callback: RampCallback) method to open the Ramp widget. This method takes
config object that you created above.
Example & Demo App
A full code example for a basic integration can be found below. You can find a demo integration showing how to integrate the Ramp SDK for Android on our Github.