Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cordova.plugins.diagnostic

dpa99c47.8kMIT7.2.3TypeScript support: included

Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.

ecosystem:cordova, cordova, android, ios, phonegap, diagnostic, wifi, location, gps, camera, bluetooth, settings

readme

Cordova diagnostic plugin Latest Stable Version Total Downloads

Overview

This Cordova/Phonegap plugin for iOS & Android is used to manage device settings such as Location, Bluetooth and WiFi. It enables management of run-time permissions, device hardware and core OS features.

The plugin is registered in on npm as cordova.plugins.diagnostic

donate

I dedicate a considerable amount of my free time to developing and maintaining this Cordova plugin, along with my other Open Source software. To help ensure this plugin is kept updated, new features are added and bugfixes are implemented quickly, please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance. Please consider donating if you're using this plugin in an app that makes you money, if you're being paid to make the app, if you're asking for new features or priority bug fixes.

Important notes

Minimum supported versions

Note: If you need to support older OS versions, please use an older version of this plugin.

Native environment required

Note that this plugin is intended for use in a native mobile environment. It will NOT work in a browser-emulated Cordova environment, for example by running cordova serve or using the Ripple emulator.

Building for Android

In order to avoid build problems with Android, please make sure you have the latest versions of the following Android SDK components installed:

  • Android SDK Tools
  • Android SDK Platform-tools
  • Android SDK Build-tools
  • Target SDK Platform - e.g. Android 10.0 (API 29)
  • Google Repository

  • Make sure you have a supported version of the cordova-android platform installed.

    • You can check if the Android platform in your Cordova project is up-to-date using cordova platform check android and if it's not, update it using cordova platform rm android && cordova platform add android@latest.
    • Since cordova.plugins.diagnostic@6 the recommended Cordova Android platform version is `cordova-android@9.0.0` (which includes AndroidX support).
    • To use this plugin with cordova-android@8, install cordova-plugin-androidx and cordova-plugin-androidx-adapter.
  • Phonegap Build uses should use the latest available CLI version (listed here) by specifying using the phonegap-version tag in your config.xml.

Installation

Using the Cordova/Phonegap/Ionic CLI

$ cordova plugin add cordova.plugins.diagnostic
$ cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0
$ phonegap plugin add cordova.plugins.diagnostic
$ ionic cordova plugin add cordova.plugins.diagnostic

AndroidX Library

This plugin uses/depends on the AndroidX (Jetpack) libraries (these supersede the Android Support Library which is no longer used by this plugin since cordova.plugins.diagnostic@6).

This plugin pins default versions of the legacy and appcompat versions of the library in its plugin.xml however you can override these to specify different versions using the ANDROIDX_VERSION (legacy) and ANDROIDX_APPCOMPAT_VERSION variables at plugin installation time, for example:

$ cordova plugin add cordova.plugins.diagnostic --variable ANDROIDX_VERSION=1.0.0 --variable ANDROIDX_APPCOMPAT_VERSION=1.3.1

Specifying modules

Since cordova.plugins.diagnostic@4 the plugin is split into optional functional modules. The reason for this is so you can choose to install only those parts of the plugin you'll use and therefore not install redundant code/components/frameworks.

By default, all the modules will be added to your project when you install the plugin.

You can specify which modules are installed by adding a <preference> to your config.xml which specifies the modules you wish to add as a space-separated list. Module names should be capitalised.

The preference takes the form:

<preference name="cordova.plugins.diagnostic.modules" value="[list of modules]" />

For example, to explicitly include all optional modules:

<preference name="cordova.plugins.diagnostic.modules" value="LOCATION BLUETOOTH WIFI CAMERA NOTIFICATIONS MICROPHONE CONTACTS CALENDAR REMINDERS MOTION NFC EXTERNAL_STORAGE" />

To install only the core module and no optional modules, leave the preference value blank:

<preference name="cordova.plugins.diagnostic.modules" value="" />

IMPORTANT: After adding the preference to your config.xml, you'll need to uninstall then re-install the plugin to your project to apply the changes:

cordova plugin rm cordova.plugins.diagnostic --nosave && cordova plugin add cordova.plugins.diagnostic --nosave

Available modules

The following optional modules are currently supported by the plugin:

IMPORTANT: It's vital that the preference be added to your config.xml before you install the plugin, otherwise the preference will not be applied and all modules will be added. This is because, due to limitations of the Cordova CLI hooks, this plugin must use the npm install process to apply the module preferences and this runs before the Cordova CLI when installing a plugin. If you change the modules specified in the preference, you'll need to uninstall then re-install the plugin to your project to apply the changes.

Reporting issues

IMPORTANT: Please read the following carefully. Failure to follow the issue template guidelines below will result in the issue being immediately closed.

Reporting a bug or problem

Before opening a bug issue, please do the following:

  • DO NOT open issues asking for support in using/integrating the plugin into your project
    • Only open issues for suspected bugs/issues with the plugin that are generic and will affect other users
    • I don't have time to offer free technical support: this is free open-source software
    • Ask for help on StackOverflow, Ionic Forums, etc.
    • Use the example project as a known working reference
    • Any issues requesting support will be closed immediately.
  • DO NOT open issues related to the Ionic Typescript wrapper for this plugin
    • This is owned/maintained by Ionic and is not part of this plugin
    • Please raise such issues/PRs against Ionic Native instead.
    • To verify an if an issue is caused by this plugin or its Typescript wrapper, please re-test using the vanilla Javascript plugin interface (without the Ionic Native wrapper).
    • Any issue opened here which is obviously an Ionic Typescript wrapper issue will be closed immediately.
  • Read the above documentation thoroughly
  • Check the CHANGELOG for any breaking changes that may be causing your issue.
  • Check a similar issue (open or closed) does not already exist against this plugin.
    • Duplicates or near-duplicates will be closed immediately.
  • When creating a new issue
    • Choose the "Bug report" template
    • Fill out the relevant sections of the template and delete irrelevant sections
    • WARNING: Failure to complete the issue template will result in the issue being closed immediately.
  • Reproduce the issue using the example project
    • This will eliminate bugs in your code or conflicts with other code as possible causes of the issue
    • This will also validate your development environment using a known working codebase
    • If reproducing the issue using the example project is not possible, create an isolated test project that you are able to share
  • Include full verbose console output when reporting build issues
    • If the full console output is too large to insert directly into the Github issue, then post it on an external site such as Pastebin and link to it from the issue
    • Often the details of an error causing a build failure is hidden away when building with the CLI
      • To get the full detailed console output, append the --verbose flag to CLI build commands
      • e.g. cordova build ios --verbose
    • Failure to include the full console output will result in the issue being closed immediately
  • If the issue relates to the plugin documentation (and not the code), please of a documentation issue

Requesting a new feature

Before opening a feature request issue, please do the following:

  • Check the above documentation to ensure the feature you are requesting doesn't already exist
  • Check the list if open/closed issues to check if there's a reason that feature hasn't been included already
  • Ensure the feature you are requesting is actually possible to implement and generically useful to other users than yourself
  • Where possible, post a link to the documentation related to the feature you are requesting
  • Include other relevant links, e.g.
    • Stack Overflow post illustrating a solution
    • Code within another Github repo that illustrates a solution

Usage

The core plugin module is exposed via the global cordova.plugins.diagnostic object and it aliases all functions and properties of the other optional modules. If a function is called on the core module for an optional module which is not installed, a JS error will be raised by the core module.

Core module

Purpose: Generic and miscellaneous functionality.

Platforms: Android & iOS

Configuration name: N/A - always installed, regardless of whether the module preference key is present in config.xml.

switchToSettings()

Platforms: Android and iOS

Opens settings page for this app.

On Android, this opens the "App Info" page in the Settings app.

On iOS, this opens the app settings page in the Settings app.

cordova.plugins.diagnostic.switchToSettings(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when switch to settings is successful.
  • {Function} errorCallback - The callback which will be called when switch to settings encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.switchToSettings(function(){
    console.log("Successfully switched to Settings app");
}, function(error){
    console.error("The following error occurred: "+error);
});

switchToWirelessSettings()

Platforms: Android

Switches to the wireless settings page in the Settings app. Allows configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks.

cordova.plugins.diagnostic.switchToWirelessSettings();

switchToMobileDataSettings()

Platforms: Android

Displays mobile settings to allow user to enable mobile data.

cordova.plugins.diagnostic.switchToMobileDataSettings();

permissionStatus constants

Platforms: Android and iOS

Both Android and iOS define constants for requesting and reporting the various permission states.

cordova.plugins.diagnostic.permissionStatus

Android

The following permission states are defined for Android:

  • NOT_REQUESTED - App has not yet requested access to this permission. App can request permission and user will be prompted to allow/deny.
  • DENIED_ONCE - User denied access to this permission (without checking "Never Ask Again" box). App can request permission again and user will be prompted again to allow/deny again.
  • DENIED_ALWAYS - User denied access to this permission and checked "Never Ask Again" box. App can never ask for permission again. The only way around this is to instruct the user to manually change the permission on the app permissions page in Settings.
  • GRANTED - User granted access to this permission or the device is running Android 5.x or below.

⚠ Since it's impossible to distinguish between NOT_REQUESTED and DENIED_ALWAYS using the native Android runtime permissions API (they both return the same constant value), this plugin attempts to distinguish the difference by using HTML5 local storage to keep track of which permissions have been requested since the app was first installed. On requesting a permission for the first time, an entry is put into local storage against the permission name. If the user then selects DENY_ALWAYS, the plugin uses the flag in local storage to distinguish this from NOT_REQUESTED.

Some things to watch out for:

  • Clearing local storage will result in this data being lost and will result in NOT_REQUESTED being returned even if the user previously chose to always deny permission.
  • If the relevant <uses-permission> tag is missing from the Android manifest, then the native API will return the NOT_REQUESTED/DENIED_ALWAYS constant value. Since the plugin is unable to make the native permissions request in order to show the native dialog, the plugin will always return NOT_REQUESTED.

If Android Autobackup is enabled (which it is by default ), Android does not backup app permissions after uninstall but does backup HTML5 local storage. This may lead to a permission being reported by the plugin as DENIED_ALWAYS when the actual status is NOT_REQUESTED. To avoid this you may want to disable Android Autobackup. You can do this using the cordova-custom-config plugin, for example:

<platform name="android">
    <plugin name="cordova-custom-config" version="*"/>
    <custom-preference name="android-manifest/application/@android:allowBackup" value="false" />
    <custom-preference name="android-manifest/application/@android:fullBackupContent" value="false" />
</platform>

iOS

The following permission states are defined for iOS:

  • NOT_REQUESTED - App has not yet requested access to this permission. App can request permission and user will be prompted to allow/deny.
  • DENIED_ALWAYS - User denied access to this permission. App can never ask for permission again. The only way around this is to instruct the user to manually change the permission in Settings.
  • RESTRICTED - Permission is unavailable and user cannot enable it. For example, when parental controls are in effect for the current user.
  • GRANTED - User granted access to this permission. For location permission, this indicates the user has granted access to the permission "always" (when app is both in foreground and background).
  • GRANTED_WHEN_IN_USE - Used only for location permission. Indicates the user has granted access to the permission "when in use" (only when the app is in the foreground).

Addtionally, for notifications permissions:

  • PROVISIONAL - The app is provisionally authorized to post non-interruptive user notifications.
  • EPHEMERAL - The app is authorized to schedule or receive notifications for a limited amount of time.

Example

if(somePermissionStatus === cordova.plugins.diagnostic.permissionStatus.GRANTED){
    // Do something
}

getPermissionAuthorizationStatus()

Platforms: Android

Returns the current authorisation status for a given permission.

Note: this is intended for Android 6 / API 23 and above. Calling on Android 5.1 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.

Parameters

  • {Function} successCallback - function to call on successful retrieval of status. The function is passed a single string parameter which defines the current permission status
  • {Function} errorCallback - function to call on failure to retrieve authorisation status. The function is passed a single string parameter containing the error message.
  • {String} permission - permission to request authorisation status for, defined as a runtime permission constant.

Example usage

cordova.plugins.diagnostic.getPermissionAuthorizationStatus(function(status){
    switch(status){
        case cordova.plugins.diagnostic.permissionStatus.GRANTED:
            console.log("Permission granted to use the camera");
            break;
        case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
            console.log("Permission to use the camera has not been requested yet");
            break;
        case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:
            console.log("Permission denied to use the camera - ask again?");
            break;
        case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
            console.log("Permission permanently denied to use the camera - guess we won't be using it then!");
            break;
    }
}, function(error){
    console.error("The following error occurred: "+error);
}, cordova.plugins.diagnostic.permission.CAMERA);

getPermissionsAuthorizationStatus()

Platforms: Android

Returns the current authorisation status for multiple permissions.

Note: this is intended for Android 6 / API 23 and above. Calling on Android 5.1 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.

Parameters

  • {Function} successCallback - function to call on successful retrieval of status. The function is passed a single object parameter which defines a key/value map, where the key is the requested runtime permission, and the value is the current permission status.
  • {Function} errorCallback - function to call on failure to retrieve authorisation status. The function is passed a single string parameter containing the error message.
  • {Array} permissions - list of permissions to request authorisation statuses for, defined as runtime permission constants.

Example usage

cordova.plugins.diagnostic.getPermissionsAuthorizationStatus(function(statuses){
    for (var permission in statuses){
        switch(statuses[permission]){
            case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                console.log("Permission granted to use "+permission);
                break;
            case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                console.log("Permission to use "+permission+" has not been requested yet");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:
                console.log("Permission denied to use "+permission+" - ask again?");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                console.log("Permission permanently denied to use "+permission+" - guess we won't be using it then!");
                break;
        }
    }
}, function(error){
    console.error("The following error occurred: "+error);
},[
    cordova.plugins.diagnostic.permission.ACCESS_FINE_LOCATION,
    cordova.plugins.diagnostic.permission.ACCESS_COARSE_LOCATION
]);

requestRuntimePermission()

Platforms: Android

Requests app to be granted authorisation for a runtime permission.

Note: this is intended for Android 6 / API 23 and above. Calling on Android 5.1 / API 22 and below will have no effect as the permissions are already granted at installation time.

Parameters

  • {Function} successCallback - function to call on successful request for runtime permission. The function is passed a single string parameter which defines the resulting permission status
  • {Function} errorCallback - function to call on failure to request authorisation. The function is passed a single string parameter containing the error message.
  • {String} permission - permission to request authorisation for, defined as a runtime permission constant.

Example usage

cordova.plugins.diagnostic.requestRuntimePermission(function(status){
    switch(status){
        case cordova.plugins.diagnostic.permissionStatus.GRANTED:
            console.log("Permission granted to use the camera");
            break;
        case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
            console.log("Permission to use the camera has not been requested yet");
            break;
        case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCe:
            console.log("Permission denied to use the camera - ask again?");
            break;
        case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
            console.log("Permission permanently denied to use the camera - guess we won't be using it then!");
            break;
    }
}, function(error){
    console.error("The following error occurred: "+error);
}, cordova.plugins.diagnostic.permission.CAMERA);

requestRuntimePermissions()

Platforms: Android

Requests app to be granted authorisation for multiple runtime permissions.

Note: this is intended for Android 6 / API 23 and above. Calling on Android 5.1 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.

Parameters

  • {Function} successCallback - function to call on successful request for runtime permissions. The function is passed a single object parameter which defines a key/value map, where the key is the runtime permission to request, and the value is the current permission status.
  • {Function} errorCallback - function to call on failure to request authorisation. The function is passed a single string parameter containing the error message.
  • {Array} permissions - list of permissions to request authorisation for, defined as runtime permission constants.

Example usage

cordova.plugins.diagnostic.requestRuntimePermissions(function(statuses){
    for (var permission in statuses){
        switch(statuses[permission]){
            case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                console.log("Permission granted to use "+permission);
                break;
            case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                console.log("Permission to use "+permission+" has not been requested yet");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:
                console.log("Permission denied to use "+permission+" - ask again?");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                console.log("Permission permanently denied to use "+permission+" - guess we won't be using it then!");
                break;
        }
    }
}, function(error){
    console.error("The following error occurred: "+error);
},[
    cordova.plugins.diagnostic.permission.ACCESS_FINE_LOCATION,
    cordova.plugins.diagnostic.permission.ACCESS_COARSE_LOCATION
]);

isRequestingPermission()

Platforms: Android

Indicates if the plugin is currently requesting a runtime permission via the native API. Note that only one request can be made concurrently because the native API cannot handle concurrent requests, so the plugin will invoke the error callback if attempting to make more than one simultaneous request. Multiple permission requests should be grouped into a single call since the native API is setup to handle batch requests of multiple permission groups.

var isRequesting = cordova.plugins.diagnostic.isRequestingPermission();

Example usage

var isRequesting = cordova.plugins.diagnostic.isRequestingPermission();
if(!isRequesting){
    requestSomePermissions();
}else{
    cordova.plugins.diagnostic.registerPermissionRequestCompleteHandler(function(statuses){
        cordova.plugins.diagnostic.registerPermissionRequestCompleteHandler(null); // de-register handler after single call
        requestSomePermissions();
    });
}

registerPermissionRequestCompleteHandler()

Platforms: Android

Registers a function to be called when a runtime permission request has completed. Pass in a falsey value to de-register the currently registered function.

cordova.plugins.diagnostic.registerPermissionRequestCompleteHandler(successCallback);

Parameters

  • {Function} successCallback - The callback which will be called when a runtime permission request has completed. The function is passed a single object parameter which defines a key/value map, where the key is the permission requested (defined as a value in cordova.plugins.diagnostic.permission) and the value is the resulting authorisation status of that permission as a value in cordova.plugins.diagnostic.permissionStatus.

Example usage

function onPermissionRequestComplete(statuses){
    console.info("Permission request complete");
    for (var permission in statuses){
        switch(statuses[permission]){
            case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                console.log("Permission granted to use "+permission);
                break;
            case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                console.log("Permission to use "+permission+" has not been requested yet");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:
                console.log("Permission denied to use "+permission);
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                console.log("Permission permanently denied to use "+permission);
                break;
        }
    }
    cordova.plugins.diagnostic.registerPermissionRequestCompleteHandler(null); // de-register handler
}
cordova.plugins.diagnostic.registerPermissionRequestCompleteHandler(onPermissionRequestComplete);

isDataRoamingEnabled()

Platforms: Android

Checks if the device data roaming setting is enabled. Returns true if data roaming is enabled. Not available on Android 12L / API 32+

cordova.plugins.diagnostic.isDataRoamingEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when the operation is successful. The function is passed a single boolean parameter which is TRUE if data roaming is enabled.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isDataRoamingEnabled(function(enabled){
    console.log("Data roaming is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isADBModeEnabled()

Platforms: Android

Checks if the device setting for ADB(debug) is switched on. Returns true if ADB(debug) setting is switched on.

cordova.plugins.diagnostic.isADBModeEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if ADB mode(debug mode) is switched on.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isADBModeEnabled(function(enabled){
    console.log("ADB mode(debug mode) is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isDeviceRooted()

Platforms: Android

Checks if the device is rooted. Returns true if the device is rooted.

cordova.plugins.diagnostic.isDeviceRooted(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if the device is rooted.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isDeviceRooted(function(rooted){
    console.log("device is " + (rooted ? "rooted" : "not rooted"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isBackgroundRefreshAuthorized()

Platforms: iOS

Checks if the application is authorized for background refresh.

cordova.plugins.diagnostic.isBackgroundRefreshAuthorized(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if background refresh access is authorized for use.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isBackgroundRefreshAuthorized(function(authorized){
    console.log("App is " + (authorized ? "authorized" : "not authorized") + " to perform background refresh");
}, function(error){
    console.error("The following error occurred: "+error);
});

getBackgroundRefreshStatus()

Platforms: iOS

Returns the background refresh authorization status for the application.

cordova.plugins.diagnostic.getBackgroundRefreshStatus(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single string parameter which indicates the authorization status as a permissionStatus constant.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.getBackgroundRefreshStatus(function(status){
    if(status === cordova.plugins.diagnostic.permissionStatus.GRANTED){
        console.log("Background refresh is allowed");
    }
}, function(error){
    console.error("The following error occurred: "+error);
});

cpuArchitecture constants

Platforms: Android and iOS

Defines constants for the various CPU architectures of the current hardware returned by getArchitecture().

cordova.plugins.diagnostic.cpuArchitecture

Android

  • UNKNOWN - Unknown CPU architecture
  • ARMv6 - ARM v6 or below (32 bit)
  • ARMv7 - ARM v7 (32 bit)
  • ARMv8 - ARM v8 (64 bit)
  • X86 - Intel x86 (32 bit)
  • X86_64 - Intel x86 (64 bit)
  • MIPS - MIPS (32 bit)
  • MIPS_64 - MIPS (64 bit)

iOS

  • UNKNOWN - Unknown CPU architecture
  • ARMv6 - ARM v6 or below (32 bit)
  • ARMv7 - ARM v7 (32 bit)
  • ARMv8 - ARM v8 (64 bit)
  • X86 - Intel x86 (32 bit)
  • X86_64 - Intel x86 (64 bit)

Example usage

See getArchitecture().

getArchitecture()

Platforms: Android and iOS

Returns the CPU architecture of the current device.

cordova.plugins.diagnostic.getArchitecture(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which indicates the location authorization status as a cpuArchitecture constant.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.getArchitecture(function(arch){
    if(arch === cordova.plugins.diagnostic.cpuArchitecture.X86
    || arch === cordova.plugins.diagnostic.cpuArchitecture.X86_64){
        console.log("Intel inside");
    }
}, function(error){
    console.error(error);
});

restart()

Platforms: Android

Restarts the application. By default, a "warm" restart will be performed in which the main Cordova activity is immediately restarted, causing the Webview instance to be recreated.

However, if the cold parameter is set to true, then the application will be "cold" restarted, meaning a system exit will be performed, causing the entire application to be restarted. This is useful if you want to fully reset the native application state but will cause the application to briefly disappear and re-appear.

Note: There is no successCallback() since if the operation is successful, the application will restart immediately before any success callback can be applied.

cordova.plugins.diagnostic.restart(errorCallback, cold);

Parameters

  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.
  • {Boolean} cold - if true the application will be cold restarted. Defaults to false.

Example usage

var onError = function(error){
    console.error("The following error occurred: "+error);
}

// Warm restart
cordova.plugins.diagnostic.restart(onError, false);

// Cold restart
cordova.plugins.diagnostic.restart(onError, true);

enableDebug()

Platforms: Android and iOS

Enables the plugin's debug mode, which logs native debug messages related to anything done with the plugin to the native and JS consoles.

  • For Android, log messages will appear in the native logcat output and in the JS console if Chrome Developer Tools is connected to the app Webview.
  • For iOS, log messages will appear in the native Xcode console output and in the JS console if Safari Web Inspector is connected to the app Webview.
  • Debug mode is initially disabled on plugin initialisation.
cordova.plugins.diagnostic.enableDebug(successCallback);

Parameters

  • {Function} successCallback - The callback which will be called when debug has been enabled.

Example usage

cordova.plugins.diagnostic.enableDebug(function(){
    console.log("Debug is enabled"));
});

getCurrentBatteryLevel()

Platforms: Android and iOS

Returns the current battery level of the device as a percentage.

cordova.plugins.diagnostic.getCurrentBatteryLevel(successCallback, successCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single int parameter which indicates the current battery level percentage.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.getCurrentBatteryLevel(function(level){
    console.log(`Current battery level is ${level}%`);
});

isAirplaneModeEnabled()

Platforms: Android

Checks if Airplane mode is currently enabled.

cordova.plugins.diagnostic.isAirplaneModeEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if Airplane mode is enabled.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isAirplaneModeEnabled(function(enabled){
    console.log(`Airplane mode is currently ${enabled ? 'enabled' : 'disabled'}`);
});

isMobileDataEnabled()

Platforms: Android

Checks if mobile (cellular) data is currently enabled in the device settings.

Requires permission <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

cordova.plugins.diagnostic.isMobileDataEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if mobile data is enabled.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isMobileDataEnabled(function(enabled){
    console.log(`Mobile data is currently ${enabled ? 'enabled' : 'disabled'}`);
});``

isMobileDataAuthorized()

Platforms: iOS

Checks if mobile data is authorized for this app.

Returns true if the per-app Mobile Data setting is set to enabled (regardless of whether the device is currently connected to a cellular network)

cordova.plugins.diagnostic.isMobileDataAuthorized(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if mobile data is authorized.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isMobileDataAuthorized(function(authorized){
    console.log(`Mobile data is currently ${authorized ? 'authorized' : 'unauthorized'}`);
});

isAccessibilityModeEnabled()

Platforms: Android and iOS

Checks if Accessibility Mode (Talkback on Android, VoiceOver on iOS) is currently enabled on the device.

cordova.plugins.diagnostic.isAccessibilityModeEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when the operation is successful. This callback function is passed a single boolean parameter which is TRUE if accessibility mode is enabled.
  • {Function} errorCallback - The callback which will be called when the operation encounters an error. This callback function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isAccessibilityModeEnabled(function(enabled){
    console.log(`Accessibility Mode is currently ${enabled ? 'enabled' : 'disabled'}`);
});

isTouchExplorationEnabled()

Platforms: Android

Checks if touch exploration (in accessibility mode) is currently enabled on the device.

cordova.plugins.diagnostic.isTouchExplorationEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when the operation is successful. This callback function is passed a single boolean parameter which is TRUE if touch exploration (in accessibility mode) is enabled.
  • {Function} errorCallback - The callback which will be called when the operation encounters an error. This callback function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isTouchExplorationEnabled(function(enabled){
    console.log(`touch exploration is currently ${enabled ? 'enabled' : 'disabled'}`);
});

getDeviceOSVersion()

Platforms: Android and iOS

Returns details of the OS of the device on which the app is currently running.

cordova.plugins.diagnostic.getDeviceOSVersion(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single object parameter with the following fields:
    • {string} version - version string of the OS e.g. "11.0"
    • {integer} apiLevel - API level of the OS e.g. 30 on Android / 16000 on iOS
    • {string} apiName - code name for API level e.g. "FROYO" on Android / "11.0" on iOS
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.getDeviceOSVersion(function(details){
    console.log(`Version: ${details.version}`); // "13.0"
    console.log(`API level: ${details.apiLevel}`); // 33
    console.log(`API name: ${details.apiName}`); // "TIRAMISU"
});

getBuildOSVersion()

Platforms: Android and iOS

Returns details of the SDK levels used to build the app.

cordova.plugins.diagnostic.getBuildOSVersion(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single object parameter with the following fields:
    • {integer} targetApiLevel - API level of the target SDK (used to build the app) e.g. 30 on Android / 16000 on iOS
    • {string} targetApiName - code name for API level of the target SDK e.g. "FROYO" on Android / "11.0" on iOS
    • {integer} minApiLevel - API level of the minimum SDK (lowest on which the app can be installed) e.g. 30 on Android / 16000 on iOS
    • {string} minApiName - code name for API level of the minimum SDK e.g. "FROYO" on Android / "11.0" on iOS
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.getBuildOSVersion(function(details){
    console.log(`Target API level: ${details.targetApiLevel}`); // 33
    console.log(`Target API name: ${details.targetApiLevel}`); // "TIRAMISU"
    console.log(`Minimum API level: ${details.targetApiLevel}`); // 21
    console.log(`Target API name: ${details.targetApiLevel}`); // "LOLLIPOP"
});

isDebugBuild()

Platforms: Android & iOS

Checks if currently running app build is a debug build.

cordova.plugins.diagnostic.isDebugBuild(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when the operation is successful. This callback function is passed a single boolean parameter which is TRUE if touch exploration (in accessibility mode) is enabled.
  • {Function} errorCallback - The callback which will be called when the operation encounters an error. This callback function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isDebugBuild(function(isDebug){
    console.log(`current app build type is: ${isDebug ? 'debug' : 'release'}`);
});

Location module

Purpose: Location/GPS functionality

Platforms: Android & iOS

Configuration name: LOCATION

locationMode constants

Platforms: Android

Defines constants for the various location modes on Android.

cordova.plugins.diagnostic.locationMode

Values

  • HIGH_ACCURACY - GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
  • BATTERY_SAVING - Network triangulation and Wifi network IDs (low accuracy)
  • DEVICE_ONLY - GPS hardware (high accuracy)
  • LOCATION_OFF - Location services disabled (no accuracy)

Example

cordova.plugins.diagnostic.getLocationMode(function(locationMode){
    switch(locationMode){
        case cordova.plugins.diagnostic.locationMode.HIGH_ACCURACY:
            console.log("High accuracy");
            break;
        case cordova.plugins.diagnostic.locationMode.BATTERY_SAVING:
            console.log("Battery saving");
            break;
        case cordova.plugins.diagnostic.locationMode.DEVICE_ONLY:
            console.log("Device only");
            break;
        case cordova.plugins.diagnostic.locationMode.LOCATION_OFF:
            console.log("Location off");
            break;
    }
},function(error){
    console.error("The following error occurred: "+error);
});

locationAuthorizationMode constants

Platforms: Android & iOS

Defines constants for the various location authorization modes on iOS and Android >= 10.

cordova.plugins.diagnostic.locationAuthorizationMode

Values

  • ALWAYS - Requires constant access to location in order to track position, even when the screen is off or the app is in the background.
  • WHEN_IN_USE - Requires access to location when the screen is on and the app is displayed.

Example

cordova.plugins.diagnostic.requestLocationAuthorization(function(status){
    console.log(status);
}, function(error){
    console.error(error);
}, cordova.plugins.diagnostic.locationAuthorizationMode.WHEN_IN_USE);

Requesting the ALWAYS permission initially with requestLocationAuthorization(), on Android 11/API 30 and iOS 13+ versions onwards is not advised and may lead to unexpected behaviour. See requestLocationAuthorization()

locationAccuracyAuthorization constants

Platforms: Android & iOS

cordova.plugins.diagnostic.locationAccuracyAuthorization

Values

  • FULL - The user authorized the app to access location data with full accuracy.
  • REDUCED - The user authorized the app to access location data with reduced accuracy.

isLocationAvailable()

Platforms: Android & iOS

Checks if app is able to access device location.

cordova.plugins.diagnostic.isLocationAvailable(successCallback, errorCallback);

On iOS this returns true if both the device setting is enabled AND the application is authorized to use location. When location is enabled, the locations returned are by a mixture GPS hardware, network triangulation and Wifi network IDs.

On Android, this returns true if Location mode is enabled and any mode is selected (e.g. Battery saving, Device only, High accuracy) AND if the app is authorised to use location. When location is enabled, the locations returned are dependent on the location mode:

  • Battery saving = network triangulation and Wifi network IDs (low accuracy)
  • Device only = GPS hardware only (high accuracy)
  • High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if location is available for use.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isLocationAvailable(function(available){
    console.log("Location is " + (available ? "available" : "not available"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isLocationEnabled()

Platforms: Android and iOS

Returns true if the device setting for location is on. On Android this returns true if Location Mode is switched on. On iOS this returns true if Location Services is switched on.

cordova.plugins.diagnostic.isLocationEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if location setting is enabled.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
    console.log("Location setting is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isGpsLocationAvailable()

Platforms: Android

Checks if high-accuracy locations are available to the app from GPS hardware. Returns true if Location mode is enabled and is set to "Device only" or "High accuracy" AND if the app is authorised to use location.

cordova.plugins.diagnostic.isGpsLocationAvailable(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if high-accuracy GPS-based location is available.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isGpsLocationAvailable(function(available){
    console.log("GPS location is " + (available ? "available" : "not available"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isGpsLocationEnabled()

Platforms: Android

Checks if the device location setting is set to return high-accuracy locations from GPS hardware. Returns true if Location mode is enabled and is set to either:

  • Device only = GPS hardware only (high accuracy)
  • High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
cordova.plugins.diagnostic.isGpsLocationEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if device setting is set to return high-accuracy GPS-based location.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
    console.log("GPS location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isNetworkLocationAvailable()

Platforms: Android

Checks if low-accuracy locations are available to the app from network triangulation/WiFi access points. Returns true if Location mode is enabled and is set to "Battery saving" or "High accuracy" AND if the app is authorised to use location.

cordova.plugins.diagnostic.isNetworkLocationAvailable(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if low-accuracy network-based location is available.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isNetworkLocationAvailable(function(available){
    console.log("Network location is " + (available ? "available" : "not available"));
}, function(error){
    console.error("The following error occurred: "+error);
});

isNetworkLocationEnabled()

Platforms: Android

Checks if location mode is set to return low-accuracy locations from network triangulation/WiFi access points Returns true if Location mode is enabled and is set to either:

  • Battery saving = network triangulation and Wifi network IDs (low accuracy)
  • High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
cordova.plugins.diagnostic.isNetworkLocationEnabled(successCallback, errorCallback);

Parameters

  • {Function} successCallback - The callback which will be called when operation is successful. The function is passed a single boolean parameter which is TRUE if device setting is set to return low-accuracy network-based location.
  • {Function} errorCallback - The callback which will be called when operation encounters an error. The function is passed a single string parameter containing the error message.

Example usage

cordova.plugins.diagnostic.isNetworkLocationEnabled(function(enabled){
    console.log("Network location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
    console.error("The following error occurred: "+error);
});

getLocationMode()

changelog

CHANGELOG

v7.2.3

  • (android) bugfix: dynamically resolve BuildConfig class (and remove hard-coded example app package name) when determining isDebugBuild()

v7.2.2

  • (ios & android) feat: add isDebugBuild()
  • fix: Separate isMobileDataEnabled() for Android vs isMobileDataAuthorized() for iOS.

v7.2.1

  • (android) fix logic in native resolution of single combined permission status in getCameraAuthorizationStatus() so it handles case where storage permissions are not requested

v7.2.0

  • (android) feat: direct getExternalSdCardDetails without permission request
    • Merged from PR #501
  • (doc) Add note about reinstalling plugin after adding modules preference to config.xml
  • (doc) Clarify functionality of enableDebug() method
    • Merged from PR #522
  • (ios) Add conditions to not use CTCellularData on Mac Catalyst.
  • (ios) feat: add switchToNotificationSettings function for iOS platform
    • Merged from PR #517
  • (ios) feat: add Resource Bundle to provide the Privacy Manifest
    • Merged from PR #516
  • (android) fix: Bump WRITE_EXTERNAL_STORAGE to 32 for camera
  • (doc) fix: recommend use of <edit-config> instead of <config-file>
    • Merged from PR #505
  • (android) fix: remove unused imports
    • Merged from PR #504
  • (doc) correct example log for Ephemeral permission granted
    • Merged from PR #503
  • (android) fix: replace deprecated StatFs functions
    • Merged from PR #502
  • (android) improve camera authorisation handling and support new behaviour in API 34 / Android 14
    • Add getCameraAuthorizationStatuses() to return the individual statuses of requested permissions related to camera
    • Change getCameraAuthorizationStatus() to natively derive the single combined status result based upon build SDK version and requested permission statuses
      • Return a LIMITED status on Android 14 if user selects limited access to photo library (return GRANTED if user selects to allow access to all)
    • Resolves #519

v7.1.4

  • (android) bugfix: decide if a permission is implicitly granted by checking if the device runtime is less than, but the build SDK used for the app is greater is or equal than, the SDK version in which the permission was added.
  • (android) tweak: throw error if a requested runtime permission is not supported by the build SDK version
  • (android) bugfix: when requesting camera permission, storage permission should also be requested by default if not specified but is currently not being

v7.1.3

  • (android) update camera module to support READ_MEDIA permissions on Android 13+
  • (android): For new runtime permissions added in API 33, consider them implicitly granted if the build SDK >= 33 and device runtime is < 33.
  • (android) fix: Return error if attempting to change Bluetooth state when build SDK >= API 33 as this is no longer support.
  • (android) fix: getExternalSdCardDetails on API 33
    • Merged from PR #495
  • (types) Using unlimited arrays in the TypeScript definition
    • Merged from PR #497

v7.1.2

  • (Android) fix: Data roaming setting not available on API 32+
  • (Android) Support new media storage permissions on Android 13 / API 33.
  • (ios) bugfix: Check argument for Photo Library Access Level is not null before attempting to perform string compare.
  • (doc) Document issue with "Only this time" option in run-time permissions on Android 11+.

v7.1.1

  • (Android, iOS) feat: Add isMobileDataEnabled() to core module.
  • (iOS) bugfix: Only allow Bluetooth permission request if not already requested.
  • (iOS) bugfix: Resolve the correct authorization status after requesting camera roll authorization and granting LIMITED access.

v7.1.0

  • (Android, iOS) feat: add support to fetch device OS and build SDK details

v7.0.0

  • (Android) BREAKING chore: Remove deprecated aliases cordova.plugins.diagnostic.runtimePermission and cordova.plugins.diagnostic.runtimePermissionStatus
    • Use cordova.plugins.diagnostic.permission and cordova.plugins.diagnostic.permissionStatus instead.
  • (iOS) feat: Add support for Photo Library access levels on iOS 14+
    • Resolves #473.
    • Add support to show Limited-Library Selection UI for Photo Roll in iOS 14+
  • (Android) feat: Add isAirplaneModeEnabled() to check if airplane mode is enabled on the device.
  • (iOS) feat: add support for checking Bluetooth authorization status on iOS
  • (Android) feat: Add support Bluetooth run-time permissions on API 31+
    • Merged from PR #465
  • (Android) BREAKING fix: Update location API for approximate vs precise location permission on Android 12+
  • (Android) fix: Update Android Location module to use LocationManager instead of Settings.Secure.LOCATION_MODE for APIs 28 and higher.
    • Merged from PR #466
  • (iOS) BREAKING fix: If getLocationAccuracyAuthorization() is called on <iOS 14, return FULL accuracy to success handler (instead of invoking error handler).
  • (iOS) fix: expose and document EPHEMERAL and PROVISIONAL authorization statues for iOS notifications.
  • (Android) fix Add support for all dangerous (runtime) permissions up to API 33.
  • (Android) bugfix: fix cold restart for API 29+
  • (Windows) BREAKING chore: Remove support for deprecated Windows 10 Mobile platform
  • (Build) fix: Bump minimist to v1.2.6 to prevent security issues
    • Merged from PR #464

v6.1.1

  • Assorted type corrections
    • Merged from PR #446
    • Pin colors to 1.4.0

v6.1.0

  • (Android, iOS) Add getCurrentBatteryLevel() to core module to retrieve current device battery level.

v6.0.4

  • (iOS) Add support for Provisional and Ephemeral notification permission statuses,
    • Merged from PR #437
  • (Android) Add support for ACTIVITY_RECOGNITION runtime permission
    • Merged from PR #430
  • (Android) Add switchToNotifications()
    • Merged from PR #434
  • (Android): Add separate plugin variable for AndroidX appcompat vs legacy version and pin to exact version numbers.

v6.0.3

  • (iOS) Update assertion to require NSLocationAlwaysAndWhenInUseUsageDescription instead of NSLocationAlwaysUsageDescription since the latter is deprecated since iOS 11.
  • Fix docs referring to NOT_REQUESTED constant
    • Merged from PR #414
  • (Android) Fix issues with background location permission when running on less than Android API 29 / 10.0.

v6.0.2

  • (iOS) Update location accuracy authorization logic based on iOS 14 Beta 3.

v6.0.1

  • (iOS, bug fix): Fix handling of conditional logic for iOS version in location module.

v6.0.0

  • (iOS) Support new location accuracy authorization API on iOS 14+.
  • (Android) BREAKING CHANGE: Migrate to AndroidX from Android Support Library
  • (iOS) BREAKING CHANGE: Remove conditional code to support iOS <= 9

v5.0.2

  • (Android) Add support for background location permission on Android 10 / API 29. Resolves #398.
  • (Doc) Add doc about locationAuthorizationMode constants
  • (Doc) Fix error in hasBluetoothSupport() example
  • (Doc) Fix enableDebug() for iOS note
  • (iOS) Add return statement to getBackgroundRefreshStatus following handling of an exception raised when attempting to retrieve status. Resolves #389.
  • (iOS): If motion tracking is not available on the device, return "not available" when calling getMotionAuthorizationStatus(). Further resolves #372.

v5.0.1

  • Add types for various statuses constants (thanks to @fcamblor)
  • (iOS) Add placeholder NSBluetoothAlwaysUsageDescription to Bluetooth module.
  • (iOS) Only initialise the native Bluetooth manager on calling a plugin API operation in the Bluetooth module.
    • This is necessary because on iOS 13, since initialising the Bluetooth manager implicitly requests runtime access to Bluetooth, presenting the user with a permission dialog.
    • Fixes #365.
  • (iOS): Fix setting/getting of persistent user settings so motion permission status is correctly determined. Fixes #372.

v5.0.0

  • BREAKING CHANGE - Align permission status constants between iOS and Android platforms. Resolves #230.

v4.0.12

  • Enable default version of Android Support Library to be overridden at plugin installation via ANDROID_SUPPORT_VERSION plugin variable. Resolves #338.
  • Bump default Android Support Library version to 28.+ to match `cordova-android@8.0.0`.

v4.0.11

  • Bug fix: On Android, count number of available cameras in order to determine if camera is present (since FEATURE_CAMERA can't be relied upon). Resolves #339.

v4.0.10

  • Bug fix: return string instead of object to success function after requesting single runtime permission on Android. Fixes #324.

v4.0.9

  • Add minimum version restriction on Cordova CLI and platforms to prevent anomalous issues being reported due to outdated Cordova environment. Resolves #323.

v4.0.8

  • iOS build fix: Make static the definition of the diagnostic variable which references the Diagnostic singleton instance to prevent it leaking to global scope and causing duplicate symbol build errors. Fixes #308.
  • Fix typo which references wrong namespace. See #306.

v4.0.7 Use native SharedPreferences to track request permissions (instead of HTML5 Local Storage) in order to avoid issues with Android Autobackup. Fixes #304.

v4.0.6

  • Remove obselete windows-target-version preference which is causing Window platform build failure. Fixes #295.
  • Add missing call to getMotionAuthorizationStatus() in iOS motion module.

v4.0.5

  • Bug fix: ensure complete camera module inclusion and default Info.plist strings on iOS. Merges #292.

v4.0.4

  • Ensure all Android code entry points are handled in try/catch blocks to prevent app crashes by unhandled exceptions.
  • Enable the types parameter for requestRemoteNotificationsAuthorization to be omitted (rather than requiring empty object). Fixes #286.

v4.0.3

  • Remove literal angle brackets in comment attributes as they cause XML parse issue in Visual Studio. Fixes #284.

v4.0.2

  • Add <uses-permission> manifest entry for Bluetooth since registering broadcast receiver is now done at runtime. Fixes #282/#283.

v4.0.1

v4.0.0

  • Major rework of plugin code (both native and JS) into separate modules.
    • Adds mechanism for including optional modules via config preference.
    • Resolves #181.
  • Removed deprecated iOS method requestAndCheckMotionAuthorization()

v3.9.2

  • Run iOS plugin initialisation on-load (rather than on-demand) to avoid race conditions when querying async native managers such as Bluetooth. Fixes #271.
  • Run all iOS native plugin commands on a background thread (other than those which call methods on [UIApplication sharedApplication] so must explicitly run on the main thread) to prevent THREAD WARNING messages in the console. Fixes #272.

v3.9.1

  • Declare Objective-C constants as static. Fixes #270.

v3.9.0

  • Add requestRemoteNotificationsAuthorization() for iOS. Resolves #269.
  • Add remoteNotificationType constants for iOS to enumerate the various notification types when checking with getRemoteNotificationsAuthorizationStatus() or requesting with requestRemoteNotificationsAuthorization().
  • Minor refactor/code cleanup of native iOS implementation.

v3.8.1

  • Use if else instead of switch on CPU arch strings for backward-compatibility to Java 6. PR #263. Fixes #264.

v3.8.0

  • Add enableDebug() to Android and iOS which outputs native plugin debug messages to native and JS consoles.
  • Add restart() to Android which warm/cold restarts the app.
  • Add getArchitecture() to Android and iOS to return the CPU architecture of the current device.

v3.7.3

  • Revert "add switchToLocationSettings to iOS" (PR #223 / commit 74e1d97939a3f7d3d14424761100d4506b55afa6). Resolves #262.

v3.7.2

  • Fix Android build errors due to stricter checks on WifiManager reference. Fixes #251.

v3.7.1

  • Set Android Support Library version to v26.+. Fixes #240 - again!

v3.7.0

  • Adds isADBmodeEnabled() and isDeviceRooted() for Android (thanks to wangjian2672)
  • Adds isDataRoamingEnabled() for Android (thanks to dukhanov)
  • Calls isRegisteredForRemoteNotifications on background thread for iOS 11. Fixes #238.
  • Rewrites Motion Tracking authorization for iOS to fix bugs and edge cases (see #197).
    • Splits requestAndCheckMotionAuthorization() into requestMotionAuthorization() and getMotionAuthorizationStatus().
      • getMotionAuthorizationStatus() returns the current authorization status only and does not request permission if it has not already been requested.
      • requestMotionAuthorization() should now only be called once when motionStatus is NOT_REQUESTED. Calling more than once will invoke the error callback.
    • Adds cordova.plugins.diagnostic.motionStatus constants to full describe authorization states.
    • Deprecates requestAndCheckMotionAuthorization(). Calling this will invoke requestMotionAuthorization() but also generate a console warning.

v3.6.7

  • Adds isRemoteNotificationsEnabled() for Android (in addition to iOS).
  • Adds getRemoteNotificationsAuthorizationStatus() for iOS 10+.

v3.6.6 Adds switchToLocationSettings() for iOS.

v3.6.5 Pin Android Compat and Support library deps to v25.+ to prevent unwanted v26 alpha/beta versions from being pulled in.

v3.6.4 Fix Android bug with legacy API signatures for Camera functions, where 3rd argument (externalStorage) is false.

v3.6.3 Fix iOS bug causing location state change handlers to erroneously trigger early. Fixes #185 for iOS.

v3.6.2 Fix bug in mapping of legacy camera API function signatures for iOS and Windows.

v3.6.1 Fix bug in mapping of legacy camera API function signatures for Android.

v3.6.0

  • Undeprecate legacy camera API and support multiple call signatures for camera API methods for the benefit of ionic-native wrapper.

v3.5.0

  • Enable option to request/check only CAMERA permission on Android when using camera methods. Fixes #178.

v3.4.2

  • Check Android SDK version for attempting to check for Bluetooth LE Peripheral support
  • Support isWifiEnabled on iOS

v3.4.1

  • Add missing export. Fixes #173
  • Add missing NFC state constant and cordova reference to typings

v3.4.0

  • Add notes for Phonegap Build regarding setting latest CLI version and PGB example project. Clarifies #168.
  • customize to add api for requestExternalStorage permission for android
  • Standardize and document Android external storage permissions convenience methods.
  • Support for Android external SD card details
  • Add NFC operations for Android to check for NFC hardware, if NFC is enabled and open NFC settings page
  • Adds NFC state change monitoring.

v3.3.3

  • Update docs regarding Android SDK component versions

v3.3.2

  • Wrap motion handlers in try/catch to prevent unhandled errors causing native crash.
  • Test for presence of CMPedometer.isPedometerEventTrackingAvailable() before attempting to call it, since it was only added in iOS 10 but CMPedometer was added in iOS 8.

v3.3.1

  • Remove erroneous wrapping of iOS JS in require module (since Cordova does this dynamically)

v3.3.0

  • Add type definitions and tests
  • Add download and version badges
  • Return current (rather than cached) Bluetooth state.
  • Add requestBluetoothAuthorization() for iOS
  • Add support for requesting and checking motion tracking authorization on iOS.
  • Add notes indicating which functions require which usage descriptions for iOS.
  • Document how to handle outcome of requesting Bluetooth authorization

v3.2.2

  • Fix switchToSettings for iOS 9. Resolves #127.
  • Fix isRemoteNotificationsEnabled() and isRemoteNotificationsEnabled() for iOS 9. Resolves #129.

v3.2.1

  • Conditionally include UserNotifications framework only for iOS 10+ to prevent errors in older versions.
  • Move imports to Diagnostic.h
  • Use conditional compiler comments to wrap iOS 10-specific code to prevent compiler errors on XCode 7
  • Add note on v3.2 build requirements. Resolves #124.
  • Fix erroneous early invocation of requestLocationAuthorization callback on iOS. Fixes #123.

v3.2.0

  • Add missing usage description for reminders (required by iOS 10).
  • Add UserNotifications framework to enable diagnostics of remote (push) notifications on iOS 10.
  • Rework remote notifications diagnostics to use new UserNotifications framework in iOS 10+. Fixes #121.
  • Rework sending of plugin results to factorise out common code.
  • Add iOS-version conditionality to fix deprecation warnings in iOS 10.

v3.1.7

  • Adds NSContactsUsageDescription (iOS10)

v3.1.6

  • Add new iOS usage description keys, as now required by iOS 10 to prevent build rejection on submission to App Store. Fixes #116.

v3.1.5

  • Bug fix: getMicrophoneAuthorizationStatus() returns "granted" but the Diagnostic.permissionStatus.GRANTED constant is "authorized"

v3.1.4

  • Add missing reference to Contacts framework for iOS. Resolves #106.
  • Add missing initialisation of contacts store (introduce by pull request #98). Fixes #113.
  • Enable de-registering of existing handler functions by passing an falsey value.
  • Prevent multiple runtime permission requests on Android using a semaphore. Resolves #99.
  • Add functions to listen for completion of runtime permission requests and to indicate if a permission request is in progress.

v3.1.3

  • Fixed iOS Warnings for deprecations

v3.1.2

  • Unpin major version of Android support library to enable latest SDK version to be used. Resolves #105.

v3.1.1

  • Return current (rather than cached) state of Bluetooth adapter on Android. Fixes #97.
  • Add empty locationAuthorizationMode object to Android implementation. Resolves #90.
  • Add support for checking iOS background refresh authorization status. Resolves #95

v3.1.0

NOTE: This version contains backwardly-incompatible renaming of some functions. Either fix the version of the plugin in your config.xml to `cordova.plugins.diagnostic@3.0` or update your code to use the revised names below.

  • Revised function names to logically separate those which check if device OS setting is enabled (isSomethingEnabled()) vs those which check if hardware/sensor is available for use by the app (device OS setting is enabled AND app has authorisation AND hardware is present - isSomethingAvailable()).
    • Renamed isLocationEnabled() => isLocationAvailable() (Android, iOS and Windows 10 Mobile) - if location is available to app
    • Renamed isLocationEnabledSetting() => isLocationEnabled() (iOS) - if device setting for location is enabled
    • Added isLocationEnabled() (Android) - if device setting for location is enabled
    • Renamed isCameraEnabled() => isCameraAvailable() (Android, iOS and Windows 10 Mobile) - if camera is available to app
    • Renamed isBluetoothEnabled() => isBluetoothAvailable() (Android, iOS and Windows 10 Mobile) - if Bluetooth is available to app
    • Added isBluetoothEnabled() (Android) - if the device setting for Bluetooth is enabled
    • Renamed isGpsLocationEnabled() => isGpsLocationAvailable() (Android) - if GPS location is available to app
    • Added isGpsLocationEnabled() (Android) - if device setting for GPS location is enabled
    • Renamed isNetworkLocationEnabled() => isNetworkLocationAvailable() (Android) - if network location is available to app
    • Added isNetworkLocationEnabled() (Android) - if device setting for network location is enabled

v3.0.3

  • Fix for #80, where change in Location Mode on Android would cause exception if plugin has not been initialised by a call from JS.

v3.0.2

  • Updated plugin and documentation to explicitly support only Windows 10 Mobile (and not Windows Phone 8.x)

v3.0.1

  • Fixed Android issues for apps not using Bluetooth state listening

v3.0.0

  • Added permissions management for Contacts and Calendar to Android & iOS
  • Added permissions management for Reminders to iOS
  • Enable registration of listeners to be notified of location and Bluetooth state changes on Android and iOS
  • Replace string literals returned with constants

Backward-incompatibility with v2

In order to make cross-platform use of the shared plugin functions easier, some backwardly-incompatible changes have been made to existing API functions.

To avoid breaking existing code which uses the old API syntax, you can continue to use the v2 API by specifying the plugin version when adding it: cordova.plugins.diagnostic@2

v3 contains the following backwardly-incompatible changes:

iOS:

  • requestCameraAuthorization() and requestMicrophoneAuthorization(): success callback is now passed a {string} referencing the permissionStatus constants instead of a {boolean}

v2.3.16

  • Update Android variant of camera authorization methods to request CAMERA permission in addition to READ_EXTERNAL_STORAGE. This is due to permission changes in cordova-plugin-camera@2.2.0.

v2.3.15

  • Add checks for Bluetooth Low Energy (LE) and Bluetooth LE Peripheral Mode to Android
  • Fix bug causing getMicrophoneAuthorizationStatus() to always return NOT_DETERMINED

v2.3.14

  • Add support for checking and requesting microphone access to Android and iOS
  • Document current quirks with requestCameraAuthorization() on Android.

v2.3.13

  • Fix erroneous reference to invalidPermissions. Fixes #42.
  • Document deprecation of registerLocationAuthorizationStatusChangeHandler()

v2.3.12

  • Simplify the handling of user response to location authorization request on iOS. Fixes #35.

v2.3.11

  • Callback to JS in WebView-agnostic way from iOS native
  • Change so only one location permission type is needed more location to be authorized on Android
  • Robustify check for UIApplicationOpenSettingsURLString. Fixes #34.
  • Update docs regarding requestLocationAuthorization on iOS vs Android. Improves #35 but doesn't entirely fix it.
  • Fixed requestCameraAuthorization returning DENIED_ALWAYS when access is granted on Android

v2.3.10

  • Update documentation regarding Android API version and legacy API 22 branch

v2.3.9

  • Ensure plugin methods return boolean true/false (not integer 0/1). Fixes #28.

v2.3.0

This version updates the plugin to support Android 6 (API 23) runtime permissions.

In order to do this it must depend on libraries only present in API 23+, so you must build using Android SDK Platform v23 or above. To do this you must have Cordova Android platform@5.0.0 or above installed in your project. You can check the currently installed platform versions with the following command:

cordova platform ls

Currently the default version installed (if not specified) is cordova-android@4 which uses API 22, so you need to explicitly specify the version when adding the platform:

cordova platform add android@5.0.0

Note: Attempting to build with API 22 or below will result in a build error.

You must also make sure your build environment has the following Android libraries installed. In a local build environment, you'd install these via the Android SDK Manager:

  • Android Support Library - Rev. 23 or above
  • Android Support Repository - Rev. 23 or above

v2.2.4

  • Added support for Windows 10 Mobile

v2.2.2

  • Add getLocationMode() for Android

v2.2.1

  • Note about Cordova Plugin Repo deprecation

v2.2.0

  • Add bluetooth state change handlers
  • Add documentation for new iOS functions
  • Add functionality to request camera roll authorization on iOS.

v2.1.0

  • Rework iOS location authorization to return authorization status
  • Add iOS camera authorization functionality

v1.1.1

  • Add switchToSettings() method for iOS
  • Enable switching to settings screens on Android
  • Split JS component into platform-specific versions
  • Update documentation to clarify Android location state
  • Added documentation for isBluetoothEnabled()
  • Added isBluetoothEnabled() for iOS
  • Add isBluetoothEnabled() for Android