Android Integration
On this page you'll find integration guides for Android platforms. Use the tabs to pick your framework.
- Java
- Kotlin
- Kotlin Compose
- React Native
- Expo
Java Integration
Consent URL: https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp
Basic Implementation
import android.content.Intent;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Button;
public class ConsentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consent);
Button openButton = findViewById(R.id.open_consent_button);
openButton.setOnClickListener(v -> openConsent());
}
private void openConsent() {
String consentUrl = "https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(consentUrl));
startActivity(intent);
}
}
Deep Link Handling
Configure AndroidManifest.xml:
<activity
android:name=".ConsentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="consent"
android:path="/callback" />
</intent-filter>
</activity>
Handle callbacks in ConsentActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consent);
handleDeepLink(getIntent());
}
private void handleDeepLink(Intent intent) {
Uri uri = intent.getData();
if (uri != null && "myapp".equals(uri.getScheme()) && "consent".equals(uri.getHost())) {
String status = uri.getQueryParameter("status");
String receiptId = uri.getQueryParameter("receiptId");
String crId = uri.getQueryParameter("crId");
Log.d("ConsentActivity", "Consent completed with status: " + status);
Log.d("ConsentActivity", "Receipt ID: " + receiptId + ", CR ID: " + crId);
if (status != null) {
// Handle consent completion
handleConsentResult(status, receiptId, crId);
}
}
}
private void handleConsentResult(String status, String receiptId, String crId) {
// Update UI based on consent result
}
Kotlin Integration
Consent URL: https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp
Basic Implementation
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
class ConsentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_consent)
val openButton = findViewById<Button>(R.id.open_consent_button)
openButton.setOnClickListener {
openConsent()
}
}
private fun openConsent() {
val consentUrl = "https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp"
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(consentUrl)
}
startActivity(intent)
}
}
Deep Link Handling
Configure AndroidManifest.xml:
<activity
android:name=".ConsentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="consent"
android:path="/callback" />
</intent-filter>
</activity>
Handle callbacks in ConsentActivity.kt:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_consent)
handleDeepLink(intent)
}
private fun handleDeepLink(intent: Intent?) {
val uri = intent?.data
if (uri != null && uri.scheme == "myapp" && uri.host == "consent") {
val status = uri.getQueryParameter("status")
val receiptId = uri.getQueryParameter("receiptId")
val crId = uri.getQueryParameter("crId")
Log.d("ConsentActivity", "Consent completed with status: $status")
Log.d("ConsentActivity", "Receipt ID: $receiptId, CR ID: $crId")
}
}
Kotlin Compose Integration
Consent URL: https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp
Basic Implementation
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import android.content.Intent
import android.net.Uri
@Composable
fun ConsentButton() {
val context = LocalContext.current
Button(onClick = {
val consentUrl = "https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp"
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(consentUrl)
}
context.startActivity(intent)
}) {
Text("Open Consent")
}
}
Deep Link Handling
Configure AndroidManifest.xml:
<activity
android:name=".ConsentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="consent"
android:path="/callback" />
</intent-filter>
</activity>
Handle callbacks in MainActivity.kt:
import androidx.compose.runtime.LaunchedEffect
import android.net.Uri
import androidx.navigation.NavHostController
@Composable
fun ConsentApp(navController: NavHostController) {
val context = LocalContext.current
LaunchedEffect(Unit) {
val currentActivity = context as? Activity
val intent = currentActivity?.intent
if (intent?.action == Intent.ACTION_VIEW) {
val uri: Uri? = intent.data
if (uri != null && uri.scheme == "myapp" && uri.host == "consent") {
val status = uri.getQueryParameter("status")
val receiptId = uri.getQueryParameter("receiptId")
val crId = uri.getQueryParameter("crId")
Log.d("ConsentApp", "Consent completed: $status")
navController.navigate("consent_result/$status")
}
}
}
ConsentButton()
}
React Native Integration
Consent URL: https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp
Basic Implementation
import { Linking, Button, View } from 'react-native';
export default function ConsentScreen() {
const openConsent = () => {
Linking.openURL('https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp').catch(err =>
console.error('Failed to open URL:', err)
);
};
return (
<View>
<Button title="Open Consent" onPress={openConsent} />
</View>
);
}
Deep Link Handling
Configure AndroidManifest.xml:
<activity
android:name=".ConsentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="consent"
android:path="/callback" />
</intent-filter>
</activity>
Configure Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.example.myapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>
Listen for callbacks:
import { useEffect } from 'react';
import { Linking } from 'react-native';
export default function App() {
useEffect(() => {
const subscription = Linking.addEventListener('url', handleDeepLink);
Linking.getInitialURL().then((url) => {
if (url != null) {
handleDeepLink({ url });
}
});
return () => subscription.remove();
}, []);
const handleDeepLink = ({ url }) => {
if (url.includes('myapp://consent/callback')) {
const params = new URLSearchParams(url.split('?')[1]);
const status = params.get('status');
const receiptId = params.get('receiptId');
const crId = params.get('crId');
console.log('Consent completed:', { status, receiptId, crId });
}
};
}
Expo Integration
Consent URL: https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp
Basic Implementation
import * as Linking from 'expo-linking';
import { Button } from 'react-native';
export default function ConsentScreen() {
return (
<Button
title="Open Consent Window"
onPress={() => Linking.openURL('https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp')}
/>
);
}
Deep Link Handling
Configure in app.json:
{
"expo": {
"scheme": "myapp",
"plugins": [
[
"expo-url-handler",
{
"scheme": "myapp"
}
]
]
}
}
Listen for callbacks:
import { useEffect } from 'react';
import * as Linking from 'expo-linking';
export default function App() {
useEffect(() => {
const subscription = Linking.addEventListener('url', handleDeepLink);
return () => subscription.remove();
}, []);
const handleDeepLink = ({ url }) => {
const route = url.replace(/.*?:\/\//g, '');
if (route.startsWith('consent/callback')) {
const params = new URLSearchParams(route.split('?')[1]);
const status = params.get('status');
const receiptId = params.get('receiptId');
const crId = params.get('crId');
console.log('Consent completed:', { status, receiptId, crId });
}
};
}