> For the complete documentation index, see [llms.txt](https://docs.somewear.app/developer-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.somewear.app/developer-docs/tak/plugin-to-plugin.md).

# Plugin to Plugin

## Messages

### Outbound

A third party plugin can send a workspace message through the Somewear plugin by broadcasting an intent.

```java
Intent intent = new Intent("com.somewearlabs.tak.message.SEND");
intent.putExtra("content", "Test outbound message");
intent.putExtra("parcelId", 123);

AtakBroadcast.getInstance().sendBroadcast(intent);
```

### Outbound Status

Outbound data and message payloads transmissions will be retried until success or a timeout occurs. You can observe terminal status changes with intents.

{% code title="HelloDropdownReceiver" %}

```java
public static final String SOMEWEAR_MESSAGE_OUTBOUND = "com.somewearlabs.tak.message.OUTBOUND";

override fun onReceive(context: Context, intent: Intent) {
    switch (action) {
        case HelloWorldDropDownReceiver.SOMEWEAR_MESSAGE_OUTBOUND: {
            String status = intent.getStringExtra("status");
            int parcelId = intent.getIntExtra("parcelId", 0);
            
            if (status.equals("Delivered")) {
                Log.d(TAG, "onReceive: did send Somewear message; parcelId=" + parcelId);
            } else if (status.equals("Error") {
        	Log.d(TAG, "onReceive: Somewear message did timeout; parcelId=" + parcelId);
            }
            
            break;
        }
    }
}
```

{% endcode %}

### Inbound

A third party plugin can listen for inbound workspace messages as well.

{% hint style="danger" %}
During development, this must first be enabled in the Somewear plugin debug menu. To show the debug menu go to **Settings > Long press on Send Logs**. Then toggle **Broadcast inbound messages**.
{% endhint %}

Once the debug option is enabled, you can listen for inbound messages by registering a BroadcastReceiver. Your plugin’s DropDownReceiver implements BroadcastReceiver already. Here’s a modified version of the [helloworld](https://git.tak.gov/samples/helloworld) sample:

{% code title="HelloWorldMapComponent" %}

```java
public static final String SOMEWEAR_MESSAGE_INBOUND = "com.somewearlabs.tak.message.INBOUND";

override fun onCreate(pluginContext: Context, intent: Intent, mapView: MapView) {
    DocumentedIntentFilter ddFilter = new DocumentedIntentFilter();
    ddFilter.addAction(HelloWorldDropDownReceiver.SHOW_HELLO_WORLD, "Show the Hello World drop-down");
    ddFilter.addAction(HelloWorldDropDownReceiver.SOMEWEAR_MESSAGE_INBOUND, "Observe inbound Somewear payloads");
    this.registerDropDownReceiver(this.dropDown, ddFilter);
}
```

{% endcode %}

{% code title="HelloWorldDropdownReceiver" %}

```java
override fun onReceive(context: Context, intent: Intent) {
    switch (action) {
        case HelloWorldDropDownReceiver.SOMEWEAR_MESSAGE_INBOUND: {
            String content = intent.getStringExtra("content");
            long timestampMillis = intent.getLongExtra("timestamp", 0L);
            Date timestamp = new Date(timestampMillis);
    				String status = intent.getStringExtra("status");
    				int parcelId = intent.getIntExtra("parcelId", 0);
            Log.d(TAG, "onReceive: did receive Somewear message; content=" + content + "; timestamp=" + timestamp + "; status=" + status);
            break;
        }
        
        case SHOW_HELLO_WORLD:
            if (!isClosed()) {
```

{% endcode %}

## Data

You can send/receive generic data payloads as well.

### Outbound

```java
byte[] data = "Just some bytes".getBytes(StandardCharsets.UTF_8);

Intent intent = new Intent("com.somewearlabs.tak.data.SEND");
intent.putExtra("data", data);

AtakBroadcast.getInstance().sendBroadcast(intent);
```

### Inbound

Unlike inbound message payloads, you don’t have to change any settings in the Somewear plugin to listen for data payloads.

{% code title="HelloWorldMapComponent" %}

```java
public static final String SOMEWEAR_DATA_INBOUND = "com.somewearlabs.tak.data.INBOUND";

override fun onCreate(pluginContext: Context, intent: Intent, mapView: MapView) {
    DocumentedIntentFilter ddFilter = new DocumentedIntentFilter();
    ddFilter.addAction(HelloWorldDropDownReceiver.SHOW_HELLO_WORLD, "Show the Hello World drop-down");
    // Observe inbound message payloads
    ddFilter.addAction(HelloWorldDropDownReceiver.SOMEWEAR_MESSAGE_INBOUND, "Observe inbound Somewear payloads");
    // Observe inbound data payloads
    ddFilter.addAction(HelloWorldDropDownReceiver.SOMEWEAR_DATA_INBOUND, "Observe inbound Somewear data payloads");
    this.registerDropDownReceiver(this.dropDown, ddFilter);
}

```

{% endcode %}
