Diagnostic
Checks whether device hardware features are enabled or available to the app, e.g. camera, GPS, wifi
Repo: https://github.com/dpa99c/cordova-diagnostic-plugin
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova.plugins.diagnostic $ npm install --save @ionic-native/diagnostic@4
- Add this plugin to your app's module
Supported platforms
- Android
- iOS
- Windows
Usage
import { Diagnostic } from '@ionic-native/diagnostic';
constructor(private diagnostic: Diagnostic) { }
...
let successCallback = (isAvailable) => { console.log('Is available? ' + isAvailable); };
let errorCallback = (e) => console.error(e);
this.diagnostic.isCameraAvailable().then(successCallback).catch(errorCallback);
this.diagnostic.isBluetoothAvailable().then(successCallback, errorCallback);
this.diagnostic.getBluetoothState()
.then((state) => {
if (state == this.diagnostic.bluetoothState.POWERED_ON){
// do something
} else {
// do something else
}
}).catch(e => console.error(e));
Instance Members
permission
permissionStatus
locationAuthorizationMode
permissionGroups
locationMode
bluetoothState
NFCState
motionStatus
isLocationAvailable()
Checks if app is able to access device location.
Returns: Promise<any>
isWifiAvailable()
Checks if Wifi is connected/enabled. On iOS this returns true if the device is connected to a network by WiFi. On Android and Windows 10 Mobile this returns true if the WiFi setting is set to enabled.
On Android this requires permission. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Returns: Promise<any>
isCameraAvailable(externalStorage)
Checks if the device has a camera. On Android this returns true if the device has a camera. On iOS this returns true if both the device has a camera AND the application is authorized to use it. On Windows 10 Mobile this returns true if both the device has a rear-facing camera AND the application is authorized to use it.
Param | Type | Details |
---|---|---|
externalStorage |
boolean
|
Android only: If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission. cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.Optional |
Returns: Promise<any>
isBluetoothAvailable()
Checks if the device has Bluetooth capabilities and if so that Bluetooth is switched on (same on Android, iOS and Windows 10 Mobile)
On Android this requires permission
Returns: Promise<any>
switchToLocationSettings()
Platforms:Android Windows 10 iOS
Displays the device location settings to allow user to enable location services/change location mode.
switchToMobileDataSettings()
Platforms:Android Windows 10
Displays mobile settings to allow user to enable mobile data.
switchToBluetoothSettings()
Platforms:Android Windows 10
Displays Bluetooth settings to allow user to enable Bluetooth.
switchToWifiSettings()
Platforms:Android Windows 10
Displays WiFi settings to allow user to enable WiFi.
isWifiEnabled()
Platforms:Android Windows 10
Returns true if the WiFi setting is set to enabled, and is the same as isWifiAvailable()
Returns: Promise<boolean>
setWifiState(state)
Platforms:Android Windows 10
Enables/disables WiFi on the device.
Requires ACCESS_WIFI_STATE
and CHANGE_WIFI_STATE
permissions on Android
Param | Type | Details |
---|---|---|
state |
boolean
|
Returns: Promise<any>
setBluetoothState(state)
Platforms:Android Windows 10
Enables/disables Bluetooth on the device.
Requires BLUETOOTH
and BLUETOOTH_ADMIN
permissions on Android
Param | Type | Details |
---|---|---|
state |
boolean
|
Returns: Promise<any>
isLocationEnabled()
Platforms:Android 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.
Returns: Promise<boolean>
isLocationAuthorized()
Checks if the application is authorized to use location. Note for Android: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
Returns: Promise<any>
getLocationAuthorizationStatus()
Platforms:Android iOS
Returns the location authorization status for the application.
Returns: Promise<any>
requestLocationAuthorization(mode)
Platforms:Android iOS
Returns the location authorization status for the application. Note for Android: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
Param | Type | Details |
---|---|---|
mode |
string
|
iOS only: location authorization mode: "always" or "when_in_use". If not specified, defaults to "when_in_use".Optional |
Returns: Promise<any>
isCameraPresent()
Platforms:Android iOS
Checks if camera hardware is present on device.
Returns: Promise<any>
isCameraAuthorized(externalStorage)
Platforms:Android iOS
Checks if the application is authorized to use the camera. Note for Android: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return TRUE as permissions are already granted at installation time.
Param | Type | Details |
---|---|---|
externalStorage |
boolean
|
Android only: If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission. cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.Optional |
Returns: Promise<any>
getCameraAuthorizationStatus(externalStorage)
Platforms:Android iOS
Returns the camera authorization status for the application.
Param | Type | Details |
---|---|---|
externalStorage |
boolean
|
Android only: If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission. cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.Optional |
Returns: Promise<any>
requestCameraAuthorization(externalStorage)
Platforms:Android iOS
Requests camera authorization for the application.
Param | Type | Details |
---|---|---|
externalStorage |
boolean
|
Android only: If true, requests permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission. cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.Optional |
Returns: Promise<any>
isMicrophoneAuthorized()
Platforms:Android iOS
Checks if the application is authorized to use the microphone.
Returns: Promise<boolean>
getMicrophoneAuthorizationStatus()
Platforms:Android iOS
Returns the microphone authorization status for the application.
Returns: Promise<any>
requestMicrophoneAuthorization()
Platforms:Android iOS
Requests microphone authorization for the application.
Returns: Promise<any>
isContactsAuthorized()
Platforms:Android iOS
Checks if the application is authorized to use contacts (address book).
Returns: Promise<boolean>
getContactsAuthorizationStatus()
Platforms:Android iOS
Returns the contacts authorization status for the application.
Returns: Promise<any>
requestContactsAuthorization()
Platforms:Android iOS
Requests contacts authorization for the application.
Returns: Promise<any>
isCalendarAuthorized()
Platforms:Android iOS
Checks if the application is authorized to use the calendar.
Notes for Android:
- This is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return TRUE as permissions are already granted at installation time.
Notes for iOS:
- This relates to Calendar Events (not Calendar Reminders)
Returns: Promise<boolean>
getCalendarAuthorizationStatus()
Platforms:Android iOS
Returns the calendar authorization status for the application.
Notes for Android:
- This is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return
GRANTED
status as permissions are already granted at installation time.
Notes for iOS:
- This relates to Calendar Events (not Calendar Reminders)
Returns: Promise<any>
requestCalendarAuthorization()
Platforms:Android iOS
Requests calendar authorization for the application.
Notes for iOS:
- Should only be called if authorization status is NOT_DETERMINED. Calling it when in any other state will have no effect and just return the current authorization status.
- This relates to Calendar Events (not Calendar Reminders)
Notes for Android:
- This is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permissions are already granted at installation time.
- This requests permission for
READ_CALENDAR
run-time permission - Required permissions must be added to
AndroidManifest.xml
as appropriate - see Android permissions:READ_CALENDAR
,WRITE_CALENDAR
Returns: Promise<any>
switchToSettings()
Platforms:Android 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. This works only on iOS 8+ - iOS 7 and below will invoke the errorCallback.
Returns: Promise<any>
getBluetoothState()
Platforms:Android iOS
Returns the state of Bluetooth on the device.
Returns: Promise<any>
registerBluetoothStateChangeHandler(handler)
Platforms:Android iOS
Registers a function to be called when a change in Bluetooth state occurs.
Param | Type | Details |
---|---|---|
handler |
Function
|
registerLocationStateChangeHandler(handler)
Platforms:Android iOS
Registers a function to be called when a change in Location state occurs.
Param | Type | Details |
---|---|---|
handler |
Function
|
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 authorized to use location.
Returns: Promise<boolean>
isGpsLocationEnabled()
Platforms:Android
Checks if location mode 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)
Returns: Promise<any>
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 authorized to use location.
Returns: Promise<any>
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)
Returns: Promise<any>
getLocationMode()
Platforms:Android
Returns the current location mode setting for the device.
Returns: Promise<any>
getPermissionAuthorizationStatus(permission)
Platforms:Android
Returns the current authorization status for a given permission. Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
Param | Type | Details |
---|---|---|
permission |
Returns: Promise<any>
getPermissionsAuthorizationStatus(permissions)
Platforms:Android
Returns the current authorization status for multiple permissions. Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
Param | Type | Details |
---|---|---|
permissions |
any[]
|
Returns: Promise<any>
requestRuntimePermission(permission)
Platforms:Android
Requests app to be granted authorization for a runtime permission. Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permissions are already granted at installation time.
Param | Type | Details |
---|---|---|
permission |
Returns: Promise<any>
requestRuntimePermissions(permissions)
Platforms:Android
Requests app to be granted authorization for multiple runtime permissions. Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
Param | Type | Details |
---|---|---|
permissions |
any[]
|
Returns: Promise<any>
isRequestingPermission()
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.
Returns: boolean
registerPermissionRequestCompleteHandler(handler)
Registers a function to be called when a runtime permission request has completed. Pass in a falsy value to de-register the currently registered function.
Param | Type | Details |
---|---|---|
handler |
Function
|
isBluetoothEnabled()
Platforms:Android
Checks if the device setting for Bluetooth is switched on.
This requires BLUETOOTH
permission on Android
Returns: Promise<boolean>
hasBluetoothSupport()
Platforms:Android
Checks if the device has Bluetooth capabilities.
Returns: Promise<boolean>
hasBluetoothLESupport()
Platforms:Android
Checks if the device has Bluetooth Low Energy (LE) capabilities.
Returns: Promise<boolean>
hasBluetoothLEPeripheralSupport()
Platforms:Android
Checks if the device supports Bluetooth Low Energy (LE) Peripheral mode.
Returns: Promise<boolean>
isExternalStorageAuthorized()
Platforms:Android
Checks if the application is authorized to use external storage.
Returns: Promise<boolean>
getExternalStorageAuthorizationStatus()
Platforms:Android
CReturns the external storage authorization status for the application.
Returns: Promise<boolean>
requestExternalStorageAuthorization()
Platforms:Android
Requests external storage authorization for the application.
Returns: Promise<any>
getExternalSdCardDetails()
Platforms:Android
Returns details of external SD card(s): absolute path, is writable, free space.
The intention of this method is to return the location and details of removable external SD cards. This differs from the “external directories” returned by cordova-plugin-file which return mount points relating to non-removable (internal) storage.
Learn more about this method here
Returns: Promise<any>
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.
switchToNFCSettings()
Platforms:Android
Displays NFC settings to allow user to enable NFC.
isNFCPresent()
Platforms:Android
Checks if NFC hardware is present on device.
Returns: Promise<boolean>
isNFCEnabled()
Platforms:Android
Checks if the device setting for NFC is switched on. Note: this operation does not require NFC permission in the manifest.
Returns: Promise<boolean>
isNFCAvailable()
Platforms:Android
Checks if NFC is available to the app. Returns true if the device has NFC capabilities AND if NFC setting is switched on. Note: this operation does not require NFC permission in the manifest.
Returns: Promise<any>
registerNFCStateChangeHandler(hander)
Platforms:Android
Registers a function to be called when a change in NFC state occurs. Pass in a falsy value to de-register the currently registered function.
Param | Type | Details |
---|---|---|
hander |
Function
|
callback function to be called when NFC state changes |
Returns: Promise<any>
isDataRoamingEnabled()
Platforms:Android
Checks if the device data roaming setting is enabled.
Returns: Promise<boolean>
isADBModeEnabled()
Platforms:Android
Checks if the device setting for ADB(debug) is switched on.
Returns: Promise<boolean>
isDeviceRooted()
Platforms:Android
Checks if the device is rooted.
Returns: Promise<boolean>
isCameraRollAuthorized()
Platforms:iOS
Checks if the application is authorized to use the Camera Roll in Photos app.
Returns: Promise<boolean>
getCameraRollAuthorizationStatus()
Platforms:iOS
Returns the authorization status for the application to use the Camera Roll in Photos app.
Returns: Promise<string>
requestCameraRollAuthorization()
Platforms:iOS
Requests camera roll authorization for the application. Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
Returns: Promise<any>
isRemoteNotificationsEnabled()
Platforms:iOS Android
Checks if remote (push) notifications are enabled.
Returns: Promise<boolean>
isRegisteredForRemoteNotifications()
Platforms:iOS
Indicates if the app is registered for remote (push) notifications on the device.
Returns: Promise<boolean>
getRemoteNotificationsAuthorizationStatus()
Platforms:iOS
Returns the authorization status for the application to use Remote Notifications. Note: Works on iOS 10+ only (iOS 9 and below will invoke the error callback).
Returns: Promise<string>
getRemoteNotificationTypes()
Platforms:iOS
Indicates the current setting of notification types for the app in the Settings app. Note: on iOS 8+, if “Allow Notifications” switch is OFF, all types will be returned as disabled.
Returns: Promise<any>
isRemindersAuthorized()
Platforms:iOS
Checks if the application is authorized to use reminders.
Returns: Promise<boolean>
getRemindersAuthorizationStatus()
Platforms:iOS
Returns the reminders authorization status for the application.
Returns: Promise<any>
requestRemindersAuthorization()
Platforms:iOS
Requests reminders authorization for the application.
Returns: Promise<any>
isBackgroundRefreshAuthorized()
Platforms:iOS
Checks if the application is authorized for background refresh.
Returns: Promise<boolean>
getBackgroundRefreshStatus()
Platforms:iOS
Returns the background refresh authorization status for the application.
Returns: Promise<any>
requestBluetoothAuthorization()
Platforms:iOS
Requests Bluetooth authorization for the application.
Learn more about this method here
Returns: Promise<any>
isMotionAvailable()
Platforms:iOS
Checks if motion tracking is available on the current device.
Returns: Promise<boolean>
isMotionRequestOutcomeAvailable()
Platforms:iOS
Checks if it’s possible to determine the outcome of a motion authorization request on the current device. There’s no direct way to determine if authorization was granted or denied, so the Pedometer API must be used to indirectly determine this: therefore, if the device supports motion tracking but not Pedometer Event Tracking, the outcome of requesting motion detection cannot be determined.
Returns: Promise<boolean>
requestMotionAuthorization()
Platforms:iOS
Requests motion tracking authorization for the application.
Learn more about this method here
Returns: Promise<string>
getMotionAuthorizationStatus()
Platforms:iOS
Checks motion authorization status for the application.
Learn more about this method here
Returns: Promise<string>