***
title: Android
slug: integration/mobile/native-android
subtitle: Seamless Transak integration for Android applications
---------------------------------------------------------------
The Transak Android integration allows you to embed a fully functional interface directly into your native Android application using Webview.
Update your `AndroidManifest.xml` to include required permissions for internet access and camera (for KYC verification):
```xml
```
Configure your MainActivity to load the Transak widget URL using your preferred implementation:
```kotlin title="Compose"
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
import android.webkit.WebView
...
AndroidView(
factory = {
WebView(it).apply {
this.layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
this.settings.javaScriptEnabled = true
this.settings.domStorageEnabled = true
this.webChromeClient = object : WebChromeClient() {
override fun onPermissionRequest(request: PermissionRequest) {
request.grant(request.resources)
}
}
}
},
update = {
it.loadUrl(
"https://global-stg.transak.com?apiKey=&sessionId="
)
}
)
```
```kotlin title="Kotlin"
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
...
transakWidgetView.run {
this.settings.javaScriptEnabled = true
this.settings.domStorageEnabled = true
this.webChromeClient = object : WebChromeClient() {
override fun onPermissionRequest(request: PermissionRequest) {
request.grant(request.resources)
}
}
loadUrl("https://global-stg.transak.com?apiKey=&sessionId=")
}
```
```java title="Java"
import android.webkit.WebView;
...
webView = (WebView) findViewById(R.id.transakWidgetView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(PermissionRequest request) {
super.onPermissionRequest(request);
request.grant(request.getResources());
}
});
webView.loadUrl("https://global-stg.transak.com?apiKey=&sessionId=");
```
Add the WebView to your `activity_main.xml` layout file:
```xml
```
Call the [Create Widget URL](/api/public/create-widget-url) to generate a Widget URL by securely passing the [widget parameters](/customization/query-parameters).
The response returns a `widgetUrl` that should be used to load Transak in Android Webview.
A `widgetUrl` is valid for 5 minutes and can only be used once. A new `widgetUrl` must be generated for every user flow.
**Example Request:**
```bash
curl --request POST \
--url https://api-gateway-stg.transak.com/api/v2/auth/session \
--header 'access-token: YOUR_ACCESS_TOKEN' \
--header 'content-type: application/json' \
--data '{
"widgetParams": {
"apiKey": "YOUR_API_KEY",
"referrerDomain": "yourdomain.com"
}
}'
```
## Use cases
Use the table below to choose the right approach for redirects, order data, and WebView events.
|
Feature
|
Approach
|
|
How to redirect users back to your app after a transaction
|
[Deeplink](#deeplinking)
|
|
How to get order data (e.g. status, order ID, amount)
|
[Deeplink](#deeplinking), [Events](#events)
|
|
Listen to WebView events (order created, widget close, etc.)
|
[Events](#events)
|
### Deeplink
Transak supports deeplinking through the use of the `redirectURL` query parameter to enable seamless navigation after the purchase/sell process is completed.
Add an intent filter to your AndroidManifest.xml to handle the deeplink:
```xml
```
Listen for the deeplink and parse the returned parameters in your Activity.
When Transak redirects back, it includes additional query parameters appended to deeplink URL mentioned [here](/customization/query-parameters#redirecturl-1).
```kotlin
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.data?.let { uri ->
val status = uri.getQueryParameter("status")
val orderId = uri.getQueryParameter("order_id")
val cryptoAmount = uri.getQueryParameter("cryptoAmount")
// Handle more parameters
}
}
```
Call the [Create Widget URL](/api/public/create-widget-url) to generate a Widget URL by securely passing the [widget parameters](/customization/query-parameters) along with the `redirectURL` parameter.
The response returns a `widgetUrl` that should be used to load Transak in Android Webview.
A `widgetUrl` is valid for 5 minutes and can only be used once. A new `widgetUrl` must be generated for every user flow.
**Example Request:**
```bash
curl --request POST \
--url https://api-gateway-stg.transak.com/api/v2/auth/session \
--header 'access-token: YOUR_ACCESS_TOKEN' \
--header 'content-type: application/json' \
--data '{
"widgetParams": {
"apiKey": "YOUR_API_KEY",
"referrerDomain": "yourdomain.com",
"redirectURL": "myapp://transak-redirect"
}
}'
```
### Events
Transak allows listening of in-widget events (like order creation, completion, and widget close) through native event handlers in Android WebViews.
Add a JavaScript interface to your WebView using the handler name Android to listen for all frontend events.
```kotlin
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
...
transakWidgetView.run {
this.settings.javaScriptEnabled = true
this.settings.domStorageEnabled = true
this.addJavascriptInterface(WebAppInterface(this@MainActivity), "Android")
this.webChromeClient = object : WebChromeClient() {
override fun onPermissionRequest(request: PermissionRequest) {
request.grant(request.resources)
}
}
loadUrl("https://global-stg.transak.com?apiKey=&sessionId=")
}
class WebAppInterface(private val context: Context) {
@JavascriptInterface
fun postMessage(eventData: String) {
Log.d("WebViewEvent", "postMessage: $eventData")
}
}
```
#### Supported Events
|
Event Name
|
Description
|
TRANSAK_WIDGET_INITIALISED
|
Widget initialised with query params
|
TRANSAK_WIDGET_OPEN
|
Widget fully loaded
|
TRANSAK_ORDER_CREATED
|
Order created by user
|
TRANSAK_ORDER_SUCCESSFUL
|
Order is successful
|
TRANSAK_ORDER_CANCELLED
|
Order is cancelled
|
TRANSAK_ORDER_FAILED
|
Order is failed
|
TRANSAK_WIDGET_CLOSE
|
Widget is about to close
|