Skip to content

molin-ai/molin-ai-android-example

Repository files navigation

Molin AI Android Example

A minimal Android app that embeds the Molin AI chat widget in a WebView. Zero third-party dependencies beyond AndroidX AppCompat.

Structure

app/src/main/
  java/ai/molin/widget/
    MainActivity.kt       — loads the WebView on launch with widget.html
  assets/
    widget.html           — loads the Molin AI chat widget from CDN
  res/
    layout/activity_main.xml — fullscreen WebView layout
  AndroidManifest.xml     — app manifest with INTERNET permission

Setup

  1. Open the project in Android Studio
  2. Replace YOUR_WIDGET_ID in app/src/main/assets/widget.html with your widget ID from the Molin dashboard
  3. Run on an emulator or device (API 24+)

How it works

The app loads a bundled HTML file (widget.html) in an Android WebView. The HTML loads the Molin widget script from CDN and renders <molin-shop-ai-chat> fullscreen.

The HTML includes a proper viewport meta tag, CSS reset, and fullscreen sizing to ensure the widget renders correctly across all Android versions and screen densities.

Close button

The show-close attribute on <molin-shop-ai-chat> renders a close button in the chat header. When tapped, the widget fires a molin-shop-ai-chat:close-click event. The HTML handles this by navigating to molin://close:

document.addEventListener('molin-shop-ai-chat:close-click', function () {
  window.location.href = 'molin://close';
});

The native side intercepts molin:// URLs via WebViewClient.shouldOverrideUrlLoading and calls finish() to close the activity. This is the same pattern used in the iOS example with WKNavigationDelegate.

Customization

  • Widget ID — change the widget attribute in widget.html
  • Close behavior — modify the molin://close handler in MainActivity.kt

Documentation

License

MIT

About

Minimal Android app embedding the Molin AI chat widget in a WebView

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors