npm package: @fttx/cordova-plugin-intent
Description: General purpose intent shim layer for cordova applications on Android. Handles various techniques for sending and receiving intents. Supports Android 14+ broadcast receiver requirements. Android 14+ compatible fork.
Author: Darryn Campbell
Latest version: 3.0.2

# Cordova Intent Plugin

[![npm version](http://img.shields.io/npm/v/@fttx/cordova-plugin-intent.svg?style=flat-square)](https://npmjs.org/package/@fttx/cordova-plugin-intent)
[![npm downloads](http://img.shields.io/npm/dm/@fttx/cordova-plugin-intent.svg?style=flat-square)](https://npmjs.org/package/@fttx/cordova-plugin-intent)
[![npm licence](http://img.shields.io/npm/l/@fttx/cordova-plugin-intent.svg?style=flat-square)](https://npmjs.org/package/@fttx/cordova-plugin-intent)

General purpose shim layer for the Android intent mechanism, exposing various ways to handle sending and receiving intents. Fully compatible with Android 14+.

## Installation

```bash
cordova plugin add @fttx/cordova-plugin-intent
```

## Android 14+ Configuration

If your app receives broadcasts from external apps (like Zebra DataWedge, barcode scanners), add this to your `config.xml`:

```xml
<platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest/application">
        <receiver android:name="com.darryncampbell.cordova.plugin.intent.BarcodeReceiver"
                  android:exported="true">
            <intent-filter>
                <action android:name="com.symbol.datawedge.api.RESULT_ACTION" />
            </intent-filter>
        </receiver>
    </config-file>
</platform>
```

**Why?** Android 14+ requires static receivers for explicit broadcasts. Add all broadcast actions your app needs to receive.

**Common actions:**

- Zebra DataWedge: `com.symbol.datawedge.api.RESULT_ACTION`
- Generic scanners: `com.scanner.broadcast`

**Verification:**

```bash
cordova build android
grep "BarcodeReceiver" platforms/android/app/src/main/AndroidManifest.xml
```

## Usage Example

```javascript
document.addEventListener("deviceready", function () {
  // Register for DataWedge broadcasts
  window.plugins.intentShim.registerBroadcastReceiver(
    {
      filterActions: ["com.symbol.datawedge.api.RESULT_ACTION"],
    },
    function (intent) {
      var barcode = intent.extras["com.symbol.datawedge.data_string"];
      console.log("Scanned:", barcode);
    }
  );
});
```

## API Reference

### Register Broadcast Receiver

```javascript
window.plugins.intentShim.registerBroadcastReceiver(
  {
    filterActions: ["com.symbol.datawedge.api.RESULT_ACTION"],
  },
  function (intent) {
    console.log("Received:", JSON.stringify(intent.extras));
  }
);
```

### Unregister Broadcast Receiver

```javascript
window.plugins.intentShim.unregisterBroadcastReceiver();
```

### Send Broadcast

```javascript
window.plugins.intentShim.sendBroadcast(
  {
    action: "com.yourapp.ACTION",
    extras: { key: "value" },
  },
  successCallback,
  failureCallback
);
```

### On Intent (Listen for Launch Intent)

```javascript
window.plugins.intentShim.onIntent(function (intent) {
  console.log("Intent:", JSON.stringify(intent.extras));
});
```

### Start Activity

```javascript
window.plugins.intentShim.startActivity(
  {
    action: window.plugins.intentShim.ACTION_VIEW,
    url: "geo:0,0?q=London",
  },
  successCallback,
  failureCallback
);
```

### Get Intent

```javascript
window.plugins.intentShim.getIntent(function (intent) {
  console.log("Action:", intent.action);
}, failureCallback);
```

### Start Activity for Result

```javascript
window.plugins.intentShim.startActivityForResult(
  {
    action: window.plugins.intentShim.ACTION_PICK,
    url: "content://com.android.contacts/contacts",
    requestCode: 1,
  },
  function (intent) {
    console.log("Result:", intent.data);
  },
  failureCallback
);
```

### Send Result

```javascript
window.plugins.intentShim.sendResult(
  {
    extras: { result: "value" },
  },
  callback
);
```

### Package Exists

```javascript
window.plugins.intentShim.packageExists(
  "com.android.contacts",
  function (exists) {
    console.log("Installed:", exists);
  }
);
```

### Constants

```javascript
window.plugins.intentShim.ACTION_VIEW;
window.plugins.intentShim.ACTION_SEND;
window.plugins.intentShim.ACTION_CALL;
window.plugins.intentShim.ACTION_SENDTO;
window.plugins.intentShim.ACTION_GET_CONTENT;
window.plugins.intentShim.ACTION_PICK;
window.plugins.intentShim.EXTRA_TEXT;
window.plugins.intentShim.EXTRA_SUBJECT;
window.plugins.intentShim.EXTRA_STREAM;
window.plugins.intentShim.EXTRA_EMAIL;
```

## Resources

- **Issues & Support**: [GitHub Issues](https://github.com/fttx/darryncampbell-cordova-plugin-intent/issues)
- **Migration from v2.x**: [MIGRATION.md](MIGRATION.md)
- **Changelog**: [CHANGELOG.md](CHANGELOG.md)

## Credits

Fork of [com-darryncampbell-cordova-plugin-intent](https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent) by Darryn Campbell.
Android 14+ compatibility by @fttx.
MIT License.