The Broadcast plugin provides a bridge to the Android system’s Intent-based broadcast infrastructure.

Setup

The broadcast plugin is already registered in the default AppTemplate.

API

broadcast.On(action string, callback func(interface{}))

Registers a handler for a specific Android Intent action.

When the OS fires a matching intent, the plugin captures it and forwards the extras as a Go map to your callback.

broadcast.Post(action string, extras map[string]interface{})

Sends a system-wide broadcast (Intent) on the native side.

Argument Type Description
action string The Intent action string
extras map[string]interface{} Data to include in the intent extras

System Events

Auto-start on Boot

To wake up your app when the phone starts, ensure your AndroidManifest.xml includes the following:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<receiver android:name="com.sweetjuice.pkg.broadcast.BootReceiver" android:exported="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

In your Go code, you can then handle the event:

broadcast.On("android.intent.action.BOOT_COMPLETED", func(data interface{}) {
    // Start background services
})

Example

import "github.com/sweet-juice/sweetjuice/plugins/broadcast"

// Send a signal
broadcast.Post("com.myapp.ENGINE_STARTED", map[string]interface{}{
    "uptime": 0,
})

// Listen for system battery changes
broadcast.On("android.intent.action.BATTERY_LOW", func(data interface{}) {
    // Throttle intensive tasks
})