The consent plugin, targeting Android versions 5 and below, allow cordova apps to
request the user’s consent the first time they attempt to use certain plugins.
This functionality is already provided in iOS, Windows UWP and Android 6.0+. So this plugin will not come into effect on these plaforms.
Currently supported plugins
Adding and Removing the Consent Plugin
The Consent plugin is added and removed using the Cordova CLI.
cordova plugin add kapsel-plugin-consent
To remove the Consent plugin from your project, use the following command:
cordova plugin rm kapsel-plugin-consent
- kapsel-plugin-calendar
- cordova-plugin-contects
- cordova-plugin-geolocation
Adding and Removing the Consent Plugin
The Consent plugin is added and removed using the Cordova CLI.
cordova plugin add kapsel-plugin-consent
To remove the Consent plugin from your project, use the following command:
cordova plugin rm kapsel-plugin-consent
Methods
getConsentValue(service, successCallback, errorCallback)
This function retrieves the consent value of the specified service and handles it through callback
Parameters:
Name | Type | Description |
---|---|---|
service |
String | name of service |
successCallback |
function | success callback function |
errorCallback |
function | error callback function |
Example
consent.getConsentValue("Calendar", function(status) {alert(status);});
init()
This function first checks if the device is running Android 5.x or lower. Then, it overrides the respective methods of the
detected plugins installed. Call the init function on window.plugins.consent under the deviceready listener function.
listConsents(callback)
This function generates an object consisting of key-value pairs of (service, value).
The callback then handles the data.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | callback function |
setConsentValue(service, status, successCallback, errorCallback)
This function sets the consent value of the specified service
Parameters:
Name | Type | Description |
---|---|---|
service |
String | name of service |
status |
String | consent value (could be be "allow", "deny", or "unset") |
successCallback |
function | success callback function |
errorCallback |
function | error callback function |
Example
consent.setConsentValue("Calendar", "allow");
setMessage(service, message)
This function sets a message to the specified service so that this message is displayed in the popup when requesting consent.
Default is empty string.
Parameters:
Name | Type | Description |
---|---|---|
service |
String | name of service |
message |
String | message to be displayed on popup |
Example
consent.setMessage("Calendar", "Message on popup");
showConsentValues(successCallback, errorCallback)
This function passes on the currently logged information regarding consent changes to the successCallback function.
The successCallback handles how do display this data.
Parameters:
Name | Type | Description |
---|---|---|
successCallback |
function | success callback function |
errorCallback |
function | error callback function |
startMonitor(service, successCallback, errorCallback)
This function starts the monitoring of a service, so a consent popup will be displayed before the plugin code runs.
The consent value will be set to unset, which means the user has yet to decide whether to give consent.
Parameters:
Name | Type | Description |
---|---|---|
service |
String | name of service |
successCallback |
function | callback function |
errorCallback |
function | callback function |
Example
consent.startMonitor("Calendar");
stopMonitor(service, callback)
This function stops the monitoring of a service, so user consent is no longer requested
Parameters:
Name | Type | Description |
---|---|---|
service |
String | name of service |
callback |
function | callback function |
Example
consent.stopMonitor("Calendar");