{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-products/rest/elements/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial","code-snippet","json-schema","login-link"]},"type":"markdown"},"seo":{"title":"Enabling Elements for Google Android","description":"Embed DailyPay On Demand Pay into your applications with our APIs and SDKs.","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":["openapi"],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"enabling-elements-for-google-android","__idx":0},"children":["Enabling Elements for Google Android"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Like other platforms, Android requires the same two or three simple steps: Add a web view, handle events/messages, and, in some cases, authenticate the user."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-1-set-up-a-web-view","__idx":1},"children":["Step 1. Set Up a Web View"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Component used: ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.android.com/reference/kotlin/android/webkit/WebView"},"children":["WebView"]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Required Web View Configuration"},"children":[{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Enable JavaScript"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Enable Web Storage (DOM Storage)"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"web-view-sample","__idx":2},"children":["Web View Sample"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"../code-samples/android/generic-example.kt","language":"kotlin","title":"elements-in-android.kt","header":{"title":"elements-in-android.kt","controls":{"copy":{}}},"lang":"kotlin","source":"        // Step 1: Set Up a Web View\n        webView = findViewById(R.id.webView)\n\n        // Configure WebView settings\n        val webSettings: WebSettings = webView.settings\n        webSettings.javaScriptEnabled = true  // [!code highlight]\n        webSettings.domStorageEnabled = true  // [!code highlight]\n        webSettings.setSupportZoom(true) // Enable zoom controls\n        webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW // Allow mixed content (HTTP/HTTPS)\n\n        // Set a WebViewClient to handle page navigation within the WebView itself\n        webView.webViewClient = object : WebViewClient() {\n            // This method is deprecated in API 24 and later, but still useful for older devices\n            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {\n                url?.let {\n                    view?.loadUrl(it)\n                }\n                return true // Return true to indicate that the app handled the URL\n            }\n\n            // For API 24 and later\n            override fun shouldOverrideUrlLoading(view: WebView?, request: android.webkit.WebResourceRequest?): Boolean {\n                request?.url?.let { uri ->\n                    view?.loadUrl(uri.toString())\n                }\n                return true // Return true to indicate that the app handled the URL\n            }\n\n            override fun onReceivedError(view: WebView?, request: android.webkit.WebResourceRequest?, error: android.webkit.WebResourceError?) {\n                super.onReceivedError(view, request, error)\n                android.util.Log.e(\"WebView\", \"Error: ${error?.description}\")\n            }\n            override fun onReceivedHttpError(view: WebView?, request: android.webkit.WebResourceRequest?, errorResponse: android.webkit.WebResourceResponse?) {\n                super.onReceivedHttpError(view, request, errorResponse)\n                android.util.Log.e(\"WebView\", \"HTTP error: ${errorResponse?.statusCode}\")\n            }\n        }\n        ","wrapContents":true},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-2-set-up-eventmessage-handling","__idx":3},"children":["Step 2. Set Up Event/Message Handling"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"sending-events","__idx":4},"children":["Sending Events"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Method used: ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.android.com/reference/androidx/webkit/WebViewCompat#postWebMessage(android.webkit.WebView,androidx.webkit.WebMessageCompat,android.net.Uri)"},"children":["postWebMessage"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Please ",{"$$mdtype":"Tag","name":"MarkdocLoginLink","attributes":{},"children":[]}," to view this content."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"send-message-sample-code","__idx":5},"children":["Send Message Sample Code"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"../code-samples/android/generic-example.kt","language":"kotlin","title":"elements-in-android.kt","header":{"title":"elements-in-android.kt","controls":{"copy":{}}},"lang":"kotlin","source":"        // Step 2: Set Up Communications: Event/Message Handling\n        // Step 2a: Send Event to Elements\n        //\n        // Code sample coming soon\n        //\n\n        ","wrapContents":true},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"listening-for-events","__idx":6},"children":["Listening for Events"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Method used: ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)"},"children":["addJavascriptInterface"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Please ",{"$$mdtype":"Tag","name":"MarkdocLoginLink","attributes":{},"children":[]}," to view this content."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"receive-message-sample-code","__idx":7},"children":["Receive Message Sample Code"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"../code-samples/android/generic-example.kt","language":"kotlin","title":"elements-in-android.kt","header":{"title":"elements-in-android.kt","controls":{"copy":{}}},"lang":"kotlin","source":"        // Step 2b: Listen for events from Elements\n  \n        // Add JavaScript interface for postMessage\n        webView.addJavascriptInterface(object {\n            @JavascriptInterface\n            fun postMessage(message: String) {\n\t\t// Interpret response and send to DailyPay using POST /accounts\n        // See https://developer.dailypay.com/tag/Accounts#operation/createAccount\n\n\t\t// For demo - alert the response payload here.\n                runOnUiThread {\n                    AlertDialog.Builder(this@MainActivity)\n                        .setTitle(\"Message from WebView\")\n                        .setMessage(message)\n                        .setPositiveButton(\"OK\", null)\n                        .show()\n                }\n            }\n        }, \"AndroidInterface\")\n        ","wrapContents":true},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-3-set-up-user-authentication-optional","__idx":8},"children":["Step 3. Set Up User Authentication (Optional)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"../code-samples/android/generic-example.kt","language":"kotlin","title":"elements-in-android.kt","header":{"title":"elements-in-android.kt","controls":{"copy":{}}},"lang":"kotlin","source":"        // Step 3: Setup Authentication\n        //\n        // Code sample coming soon\n        //\n        ","wrapContents":true},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"full-sample-code","__idx":9},"children":["Full Sample Code"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"../code-samples/android/generic-example.kt","language":"kotlin","title":"elements-in-android.kt","header":{"title":"elements-in-android.kt","controls":{"copy":{}}},"lang":"kotlin","source":"package com.example.webviewrunner\n\nimport android.os.Bundle\nimport android.webkit.JavascriptInterface\nimport android.webkit.WebSettings\nimport android.webkit.WebView\nimport android.webkit.WebViewClient\nimport android.app.AlertDialog\nimport androidx.appcompat.app.AppCompatActivity\n\nclass MainActivity : AppCompatActivity() {\n\n    private lateinit var webView: WebView\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n\n        // Step 1: Set Up a Web View\n        webView = findViewById(R.id.webView)\n\n        // Configure WebView settings\n        val webSettings: WebSettings = webView.settings\n        webSettings.javaScriptEnabled = true  // [!code highlight]\n        webSettings.domStorageEnabled = true  // [!code highlight]\n        webSettings.setSupportZoom(true) // Enable zoom controls\n        webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW // Allow mixed content (HTTP/HTTPS)\n\n        // Set a WebViewClient to handle page navigation within the WebView itself\n        webView.webViewClient = object : WebViewClient() {\n            // This method is deprecated in API 24 and later, but still useful for older devices\n            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {\n                url?.let {\n                    view?.loadUrl(it)\n                }\n                return true // Return true to indicate that the app handled the URL\n            }\n\n            // For API 24 and later\n            override fun shouldOverrideUrlLoading(view: WebView?, request: android.webkit.WebResourceRequest?): Boolean {\n                request?.url?.let { uri ->\n                    view?.loadUrl(uri.toString())\n                }\n                return true // Return true to indicate that the app handled the URL\n            }\n\n            override fun onReceivedError(view: WebView?, request: android.webkit.WebResourceRequest?, error: android.webkit.WebResourceError?) {\n                super.onReceivedError(view, request, error)\n                android.util.Log.e(\"WebView\", \"Error: ${error?.description}\")\n            }\n            override fun onReceivedHttpError(view: WebView?, request: android.webkit.WebResourceRequest?, errorResponse: android.webkit.WebResourceResponse?) {\n                super.onReceivedHttpError(view, request, errorResponse)\n                android.util.Log.e(\"WebView\", \"HTTP error: ${errorResponse?.statusCode}\")\n            }\n        }\n        // Step 1 End\n\n        // Step 2: Set Up Communications: Event/Message Handling\n        // Step 2a: Send Event to Elements\n        //\n        // Code sample coming soon\n        //\n\n        // Step 2b: Listen for events from Elements\n  \n        // Add JavaScript interface for postMessage\n        webView.addJavascriptInterface(object {\n            @JavascriptInterface\n            fun postMessage(message: String) {\n\t\t// Interpret response and send to DailyPay using POST /accounts\n        // See https://developer.dailypay.com/tag/Accounts#operation/createAccount\n\n\t\t// For demo - alert the response payload here.\n                runOnUiThread {\n                    AlertDialog.Builder(this@MainActivity)\n                        .setTitle(\"Message from WebView\")\n                        .setMessage(message)\n                        .setPositiveButton(\"OK\", null)\n                        .show()\n                }\n            }\n        }, \"AndroidInterface\")\n        // Step 2 End\n\n        // Step 3: Setup Authentication\n        //\n        // Code sample coming soon\n        //\n        // Step 3 End\n\n        // Replace client_id and implementation_id with values supplied by DailyPay\n        // that are unique to you and your application\n        webView.loadUrl(\"https://elements.uat.dailypay.com/v1/debit-card-tokenization?client_id=REPLACE_WITH_YOUR_CLIENT_ID&implementation_id=REPLACE_WITH_YOUR_IMPLEMENTATION_ID\")\n    }\n\n    // Handle back button presses to navigate within the WebView's history\n    override fun onBackPressed() {\n        if (webView.canGoBack()) {\n            webView.goBack()\n        } else {\n            super.onBackPressed()\n        }\n    }\n}\n","wrapContents":true},"children":[]}]},"headings":[{"value":"Enabling Elements for Google Android","id":"enabling-elements-for-google-android","depth":1},{"value":"Step 1. Set Up a Web View","id":"step-1-set-up-a-web-view","depth":2},{"value":"Web View Sample","id":"web-view-sample","depth":4},{"value":"Step 2. Set Up Event/Message Handling","id":"step-2-set-up-eventmessage-handling","depth":2},{"value":"Sending Events","id":"sending-events","depth":3},{"value":"Send Message Sample Code","id":"send-message-sample-code","depth":4},{"value":"Listening for Events","id":"listening-for-events","depth":3},{"value":"Receive Message Sample Code","id":"receive-message-sample-code","depth":4},{"value":"Step 3. Set Up User Authentication (Optional)","id":"step-3-set-up-user-authentication-optional","depth":2},{"value":"Full Sample Code","id":"full-sample-code","depth":2}],"frontmatter":{"seo":{"title":"Enabling Elements for Google Android"}},"lastModified":"2026-07-14T14:30:25.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/rest/elements/developer-guide/android","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}