Android

Seamless OZZOBiT integration for Android applications

Integrate OZZOBiT into your Android application using WebView. This guide covers Kotlin and Java implementations for embedding the OZZOBiT widget in native Android apps.

Prerequisites

  • Android 5.0+ (API level 21+) with WebView support
  • A valid OZZOBiT API key from the Partner Dashboard
  • Internet permission in your AndroidManifest.xml

Installation

Add Internet Permission

Ensure your app has internet permission declared:

AndroidManifest.xmlxml
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Create OZZOBiT Activity

Create a new Activity to host the OZZOBiT WebView:

OZZOBiTActivity.ktkotlin
// OZZOBiTActivity.kt
package com.yourapp.OZZOBiT

import android.os.Bundle
import android.view.View
import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity

class OZZOBiTActivity : AppCompatActivity() {

    private lateinit var webView: WebView
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // Set content view with a full-screen WebView layout
        setContentView(R.layout.activity_OZZOBiT)
        
        webView = findViewById(R.id.OZZOBiT_webview)
        setupWebView()
    }
    
    private fun setupWebView() {
        webView.settings.apply {
            javaScriptEnabled = true
            domStorageEnabled = true
            cacheMode = android.webkit.WebSettings.LOAD_DEFAULT
            setSupportZoom(true)
            builtInZoomControls = true
            displayZoomControls = false
            loadWithOverviewMode = true
            useWideViewPort = true
            mixedContentMode = android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
            mediaPlaybackRequiresUserGesture = false
        }
        
        // Configure WebView client
        webView.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(
                view: WebView?,
                request: WebResourceRequest?
            ): Boolean {
                // Handle redirect URLs
                val url = request?.url.toString()
                if (url.startsWith("https://your-app.com/callback")) {
                    handleCallback(url)
                    return true
                }
                return false
            }
            
            override fun onPageFinished(view: WebView?, url: String?) {
                super.onPageFinished(view, url)
                // Page loaded - you can show/hide loading indicators here
            }
        }
        
        webView.webChromeClient = WebChromeClient()
        
        // Build and load the OZZOBiT URL
        val OZZOBiTUrl = buildOZZOBiTUrl()
        webView.loadUrl(OZZOBiTUrl)
    }
    
    private fun buildOZZOBiTUrl(): String {
        val params = mapOf(
            "apiKey" to "YOUR_PUBLIC_API_KEY",
            "productsAvailed" to "BUY",
            "network" to "ethereum",
            "defaultCryptoCurrency" to "ETH",
            "defaultFiatCurrency" to "USD",
            "themeColor" to "%231461db",
            "redirectURL" to "https://your-app.com/callback"
        )
        
        val queryString = params.entries
            .joinToString("&") { "${it.key}=${it.value}" }
        
        return "https://OZZOBiT.com/global?$queryString"
    }
    
    private fun handleCallback(url: String) {
        // Parse callback parameters
        val uri = android.net.Uri.parse(url)
        val status = uri.getQueryParameter("status")
        val orderId = uri.getQueryParameter("orderId")
        
        when (status) {
            "SUCCESS" -> handleSuccess(orderId!!)
            "FAILURE" -> handleFailure(orderId!!)
        }
        
        finish()
    }
    
    private fun handleSuccess(orderId: String) {
        // Handle successful order - update UI, notify user, etc.
    }
    
    private fun handleFailure(orderId: String) {
        // Handle failed order - show error message
    }
    
    override fun onBackPressed() {
        if (webView.canGoBack()) {
            webView.goBack()
        } else {
            super.onBackPressed()
        }
    }
}

Layout File

activity_OZZOBiT.xmlxml
<!-- res/layout/activity_OZZOBiT.xml -->
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:id="@+id/OZZOBiT_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

Launch from Your App

kotlinkotlin
// From any Activity or Fragment:
val intent = Intent(this, OZZOBiTActivity::class.java)
startActivity(intent)

// Or pass wallet address as extra:
intent.putExtra("walletAddress", userWalletAddress)
startActivity(intent)
⚠️
Important Notes
  • Always use HTTPS URLs for security
  • Handle network connectivity gracefully
  • Test thoroughly on different screen sizes and orientations
  • Consider adding a loading indicator while the widget loads
  • Use ProGuard/R8 rules to keep WebView classes if using code obfuscation

Handling Events via JavaScript Interface

kotlinkotlin
// For more advanced event handling, use JavaScript interface:

class OZZOBiTJavaScriptInterface(private val activity: AppCompatActivity) {
    @JavascriptInterface
    fun postMessage(jsonData: String) {
        try {
            val data = org.json.JSONObject(jsonData)
            val eventName = data.getString("eventName")
            
            activity.runOnUiThread {
                when (eventName) {
                    "ORDER_SUCCESSFUL" -> handleOrderSuccess(data)
                    "ORDER_FAILED" -> handleOrderFailed(data)
                    "CLOSE_WIDGET" -> activity.finish()
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}

// Add to WebView setup:
webView.addJavascriptInterface(
    OZZOBiTJavaScriptInterface(this),
    "OZZOBiTAndroid"
)