wails/v3/pkg/application/messageprocessor_android.go
Lea Anthony 4d8ec29feb feat: Add Android support for Wails v3
This commit adds comprehensive Android support for Wails v3, enabling
Go applications to run as native Android apps with WebView-based UI.

Key features:
- Android-specific application implementation with JNI bridge
- WebView integration via WebViewAssetLoader for serving assets
- JavaScript runtime injection and execution via JNI callbacks
- Binding call support with async result callbacks
- Event system support for Android platform
- Full example Android app with Gradle build system

Technical details:
- Uses CGO with Android NDK for cross-compilation
- Implements JNI callbacks for Go <-> Java communication
- Supports both ARM64 and x86_64 architectures
- WebView debugging support via Chrome DevTools Protocol
- Handles empty response body case in binding calls to prevent panic

Files added:
- v3/pkg/application/*_android.go - Android platform implementations
- v3/pkg/events/events_android.go - Android event definitions
- v3/internal/*/\*_android.go - Android-specific internal packages
- v3/examples/android/ - Complete example Android application
- v3/ANDROID_ARCHITECTURE.md - Architecture documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 21:06:59 +11:00

74 lines
1.9 KiB
Go

//go:build android
package application
import (
"fmt"
"net/http"
)
const (
AndroidHapticsVibrate = 0
AndroidDeviceInfo = 1
AndroidToast = 2
)
var androidMethodNames = map[int]string{
AndroidHapticsVibrate: "Haptics.Vibrate",
AndroidDeviceInfo: "Device.Info",
AndroidToast: "Toast.Show",
}
func (m *MessageProcessor) processAndroidMethod(method int, rw http.ResponseWriter, r *http.Request, window Window, params QueryParams) {
switch method {
case AndroidHapticsVibrate:
args, _ := params.Args()
duration := 100 // default 100ms
if d := args.Int("duration"); d != nil {
duration = *d
}
androidHapticsVibrate(duration)
m.ok(rw)
case AndroidDeviceInfo:
m.json(rw, androidDeviceInfo())
case AndroidToast:
args, _ := params.Args()
message := ""
if s := args.String("message"); s != nil {
message = *s
}
androidShowToast(message)
m.ok(rw)
default:
m.httpError(rw, "Invalid Android call:", fmt.Errorf("unknown method: %d", method))
return
}
m.Info("Runtime call:", "method", "Android."+androidMethodNames[method])
}
// processIOSMethod is a stub on Android
func (m *MessageProcessor) processIOSMethod(method int, rw http.ResponseWriter, r *http.Request, window Window, params QueryParams) {
m.httpError(rw, "iOS methods not available on Android:", fmt.Errorf("unknown method: %d", method))
}
// Android-specific runtime functions (stubs for now)
func androidHapticsVibrate(durationMs int) {
// TODO: Implement via JNI to Android Vibrator service
androidLogf("debug", "Haptics vibrate: %dms", durationMs)
}
func androidDeviceInfo() map[string]interface{} {
// TODO: Implement via JNI to get actual device info
return map[string]interface{}{
"platform": "android",
"model": "Unknown",
"version": "Unknown",
}
}
func androidShowToast(message string) {
// TODO: Implement via JNI to Android Toast
androidLogf("debug", "Toast: %s", message)
}