@fttx/cordova-plugin-intent
v3.0.2
Published
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.
Maintainers
Readme
Cordova Intent Plugin
General purpose shim layer for the Android intent mechanism, exposing various ways to handle sending and receiving intents. Fully compatible with Android 14+.
Installation
cordova plugin add @fttx/cordova-plugin-intentAndroid 14+ Configuration
If your app receives broadcasts from external apps (like Zebra DataWedge, barcode scanners), add this to your config.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:
cordova build android
grep "BarcodeReceiver" platforms/android/app/src/main/AndroidManifest.xmlUsage Example
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
window.plugins.intentShim.registerBroadcastReceiver(
{
filterActions: ["com.symbol.datawedge.api.RESULT_ACTION"],
},
function (intent) {
console.log("Received:", JSON.stringify(intent.extras));
}
);Unregister Broadcast Receiver
window.plugins.intentShim.unregisterBroadcastReceiver();Send Broadcast
window.plugins.intentShim.sendBroadcast(
{
action: "com.yourapp.ACTION",
extras: { key: "value" },
},
successCallback,
failureCallback
);On Intent (Listen for Launch Intent)
window.plugins.intentShim.onIntent(function (intent) {
console.log("Intent:", JSON.stringify(intent.extras));
});Start Activity
window.plugins.intentShim.startActivity(
{
action: window.plugins.intentShim.ACTION_VIEW,
url: "geo:0,0?q=London",
},
successCallback,
failureCallback
);Get Intent
window.plugins.intentShim.getIntent(function (intent) {
console.log("Action:", intent.action);
}, failureCallback);Start Activity for Result
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
window.plugins.intentShim.sendResult(
{
extras: { result: "value" },
},
callback
);Package Exists
window.plugins.intentShim.packageExists(
"com.android.contacts",
function (exists) {
console.log("Installed:", exists);
}
);Constants
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
- Migration from v2.x: MIGRATION.md
- Changelog: CHANGELOG.md
Credits
Fork of com-darryncampbell-cordova-plugin-intent by Darryn Campbell. Android 14+ compatibility by @fttx. MIT License.
