Cordova plugin for Android Intents and Zebra DataWedge
npm install com-easystep2-datawedge-plugin-intent-cordovaPlease be aware that this application / sample is provided as-is for demonstration purposes without any guarantee of support
=========================================================
This is an updated and maintained version of the original darryncampbell-cordova-plugin-intent plugin, now named com.easystep2.datawedge.plugin.intent-cordova.

The original plugin badges are preserved for reference:




Note: the original plugin was the underlying implementation for https://www.npmjs.com/package/@ionic-native/web-intent and https://ionicframework.com/docs/native/web-intent/
This project is also released under MIT. Credit is given in the code where appropriate.
window.plugins.intentShim object which provides an API for interacting with the Android intent mechanism on any Android device.bash
Install from npm
npm install com-easystep2-datawedge-plugin-intent-cordova
cordova plugin add com-easystep2-datawedge-plugin-intent-cordovaOr install directly from GitHub
cordova plugin add https://github.com/easystep2/easystep2-datawedge-plugin-intent.git
`$3
`bash
Install from npm
npm install com-easystep2-datawedge-plugin-intent-capacitorOr install directly from GitHub
npm install https://github.com/easystep2/easystep2-datawedge-plugin-intent.gitThen sync your project
npx cap sync
`Uninstallation
$3
`bash
cordova plugin remove com-easystep2-datawedge-plugin-intent-cordova
npm uninstall com-easystep2-datawedge-plugin-intent-cordova
`$3
`bash
npm uninstall com-easystep2-datawedge-plugin-intent-capacitor
npx cap sync
`Package Architecture
This project has been restructured to support both Cordova and Capacitor applications from a single codebase, with specific npm packages for each platform.$3
The plugin provides:
- com-easystep2-datawedge-plugin-intent-cordova for Cordova projects
- com-easystep2-datawedge-plugin-intent-capacitor for Capacitor projects
- Consistent API across both platforms
- Simplified maintenance and updates$3
If you were previously using a different version:`bash
For Cordova projects
cordova plugin remove com.easystep2.datawedge.plugin.intent
npm uninstall com.easystep2.datawedge.plugin.intent
npm install com-easystep2-datawedge-plugin-intent-cordova
cordova plugin add com-easystep2-datawedge-plugin-intent-cordovaFor Capacitor projects
npm uninstall com.easystep2.datawedge.plugin.intent
npm install com-easystep2-datawedge-plugin-intent-capacitor
npx cap sync
`Version Bump Guidelines
When bumping versions, follow semantic versioning:
- MAJOR: Breaking changes
- MINOR: New features without breaking changes
- PATCH: Bug fixes without breaking changesTroubleshooting
$3
- Intent not firing: Verify your broadcast receiver is properly registered
- Data not received: Check your intent extras format and data types
- Conflicts with other plugins: Install this plugin after other intent-related plugins
- Angular issues: For Angular 14+, use version 2.x.x or later$3
If you're using this plugin with Zebra DataWedge:
- Ensure your DataWedge profile is configured correctly
- Verify the intent output is enabled
- Confirm the intent action and category match your registration$3
- Cordova: If you experience issues with older Cordova versions, check compatibility in the plugin.xml
- Capacitor: For Capacitor 3+, ensure you're using plugin version 2.x.x or higher$3
Enable debug mode for more verbose logging:`javascript
window.plugins.intentShim.setDebugMode(true);
`Supported Platforms
- AndroidintentShim.registerBroadcastReceiver
Registers a broadcast receiver for the specified filters
window.plugins.intentShim.registerBroadcastReceiver(filters, callback);
$3
The
intentShim.registerBroadcastReceiver function registers a dynamic broadcast receiver for the specified list of filters and invokes the specified callback when any of those filters are received$3
Register a broadcast receiver for two filters:
window.plugins.intentShim.registerBroadcastReceiver({
filterActions: [
'com.easystep2.datawedge.plugin.broadcastIntent.ACTION',
'com.easystep2.datawedge.plugin.broadcastIntent.ACTION_2'
]
},
function(intent) {
console.log('Received broadcast intent: ' + JSON.stringify(intent.extras));
}
);
intentShim.unregisterBroadcastReceiver
Unregisters any BroadcastRecivers
window.plugins.intentShim.unregisterBroadcastReceiver();
$3
The
intentShim.unregisterBroadcastReceiver function unregisters all broadcast receivers registered with intentShim.registerBroadcastReceiver(filters, callback);. No further broadcasts will be received for any registered filter after this call.$3
The developer is responsible for calling unregister / register when their application goes into the background or comes back to the foreground, if desired.
$3
Unregister the broadcast receiver when the application receives an onPause event:
bindEvents: function() {
document.addEventListener('pause', this.onPause, false);
},
onPause: function()
{
window.plugins.intentShim.unregisterBroadcastReceiver();
}
intentShim.sendBroadcast
Sends a broadcast intent
window.plugins.intentShim.sendBroadcast(action, extras, successCallback, failureCallback);
$3
The
intentShim.sendBroadcast function sends an Android broadcast intent with a specified action$3
Send a broadcast intent to a specified action that contains a random number in the extras
window.plugins.intentShim.startActivity(
{
action: "com.easystep2.datawedge.plugin.intent.ACTION",
extras: {
'random.number': Math.floor((Math.random() * 1000) + 1)
}
},
function() {},
function() {alert('Failed to open URL via Android Intent')}
);
intentShim.onIntent
Returns the content of the intent used whenever the application activity is launched
window.plugins.intentShim.onIntent(callback);
$3
The
intentShim.onIntent function returns the intent which launched the Activity and maps to the Android Activity's onNewIntent() method, https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent). The registered callback is invoked whenever the activity is launched$3
By default the android application will be created with launch mode set to 'SingleTop'. If you wish to change this to 'SingleTask' you can do so by modifying
config.xml as follows:
...
See https://www.mobomo.com/2011/06/android-understanding-activity-launchmode/ for more information on the differences between the two.
$3
Registers a callback to be invoked
window.plugins.intentShim.onIntent(function (intent) {
console.log('Received Intent: ' + JSON.stringify(intent.extras));
});
intentShim.startActivity
Starts a new activity using an intent built from action, url, type, extras or some subset of those parameters
window.plugins.intentShim.startActivity(params, successCallback, failureCallback);
$3
The
intentShim.startActivity function maps to Android's activity method startActivity, https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent) to launch a new activity.$3
Some common actions are defined as constants in the plugin, see below.
$3
Launch the maps activity
window.plugins.intentShim.startActivity(
{
action: window.plugins.intentShim.ACTION_VIEW,
url: 'geo:0,0?q=London'
},
function() {},
function() {alert('Failed to open URL via Android Intent')}
);
Launch the web browser
window.plugins.intentShim.startActivity(
{
action: window.plugins.intentShim.ACTION_VIEW,
url: 'http://www.google.co.uk'
},
function() {},
function() {alert('Failed to open URL via Android Intent')}
);
intentShim.getIntent
Retrieves the intent that launched the activity
window.plugins.intentShim.getIntent(resultCallback, failureCallback);
$3
The
intentShim.getIntent function maps to Android's activity method getIntent, https://developer.android.com/reference/android/app/Activity.html#getIntent() to return the intent that started this activity.$3
window.plugins.intentShim.getIntent(
function(intent)
{
console.log('Action' + JSON.stringify(intent.action));
var intentExtras = intent.extras;
if (intentExtras == null)
intentExtras = "No extras in intent";
console.log('Launch Intent Extras: ' + JSON.stringify(intentExtras));
},
function()
{
console.log('Error getting launch intent');
});
intentShim.startActivityForResult
Starts a new activity and return the result to the application
window.plugins.intentShim.startActivityForResult(params, resultCallback, failureCallback);
$3
The
intentShim.startActivityForResult function maps to Android's activity method startActivityForResult, https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int) to launch a new activity and the resulting data is returned via the resultCallback.$3
Some common actions are defined as constants in the plugin, see below.
$3
Pick an Android contact
window.plugins.intentShim.startActivityForResult(
{
action: window.plugins.intentShim.ACTION_PICK,
url: "content://com.android.contacts/contacts",
requestCode: 1
},
function(intent)
{
if (intent.extras.requestCode == 1)
{
console.log('Picked contact: ' + intent.data);
}
},
function()
{
console.log("StartActivityForResult failure");
});
intentShim.sendResult
Assuming this application was started with
intentShim.startActivityForResult, send a result back window.plugins.intentShim.sendResult(args, callback);
$3
The
intentShim.sendResult function returns an Activity.RESULT_OK Intent to the activity that started this application, along with any extras that you want to send along (as args.extras object), and a callback function. It then calls Android Activity's finish() method, https://developer.android.com/reference/android/app/Activity.html#finish().$3
Both
args and callback arguments have to be provided. If you do not need the functionality, send an empty object and an empty function window.plugins.intentShim.sendResult({}, function() {});
$3
window.plugins.intentShim.sendResult(
{
extras: {
'Test Intent': 'Successfully sent',
'Test Intent int': 42,
'Test Intent bool': true,
'Test Intent double': parseFloat("142.12")
}
},
function() {
}
);
intentShim.packageExists
Returns a boolean indicating if a specific package is installed on the device.`js
window.plugins.intentShim.packageExists(packageName, callback);
`$3
The
intentShim.packageExists function returns a boolean indicating if a specific package is installed on the current device.$3
`js
const packageName = 'com.android.contacts';window.plugins.intentShim.packageExists(packageName, (exists) => {
if (exists) {
console.log(
${packageName} exists!);
} else {
console.log(${packageName} does not exist...);
}
});
``The following constants are defined in the plugin for use in JavaScript
- window.plugins.intentShim.ACTION_SEND
- window.plugins.intentShim.ACTION_VIEW
- window.plugins.intentShim.EXTRA_TEXT
- window.plugins.intentShim.EXTRA_SUBJECT
- window.plugins.intentShim.EXTRA_STREAM
- window.plugins.intentShim.EXTRA_EMAIL
- window.plugins.intentShim.ACTION_CALL
- window.plugins.intentShim.ACTION_SENDTO
- window.plugins.intentShim.ACTION_GET_CONTENT
- window.plugins.intentShim.ACTION_PICK
Tested with Cordova version 6.5.0 and Cordova Android version 6.2.1