UNPKG

23.2 kBTypeScriptView Raw
1/**
2 * @name Diagnostic
3 * @description
4 * Checks whether device hardware features are enabled or available to the app, e.g. camera, GPS, wifi
5 *
6 * @usage
7 * ```typescript
8 * import { Diagnostic } from 'ionic-native';
9 *
10 * let successCallback = (isAvailable) => { console.log('Is available? ' + isAvailable); };
11 * let errorCallback = (e) => console.error(e);
12 *
13 * Diagnostic.isCameraAvailable().then(successCallback).catch(errorCallback);
14 *
15 * Diagnostic.isBluetoothAvailable().then(successCallback, errorCallback);
16 *
17 *
18 * Diagnostic.getBluetoothState()
19 * .then((state) => {
20 * if (state == Diagnostic.bluetoothStates.POWERED_ON){
21 * // do something
22 * } else {
23 * // do something else
24 * }
25 * }).catch(e => console.error(e));
26 *
27 * ```
28 *
29 */
30export declare class Diagnostic {
31 static permission: {
32 READ_CALENDAR: string;
33 WRITE_CALENDAR: string;
34 CAMERA: string;
35 READ_CONTACTS: string;
36 WRITE_CONTACTS: string;
37 GET_ACCOUNTS: string;
38 ACCESS_FINE_LOCATION: string;
39 ACCESS_COARSE_LOCATION: string;
40 RECORD_AUDIO: string;
41 READ_PHONE_STATE: string;
42 CALL_PHONE: string;
43 ADD_VOICEMAIL: string;
44 USE_SIP: string;
45 PROCESS_OUTGOING_CALLS: string;
46 READ_CALL_LOG: string;
47 WRITE_CALL_LOG: string;
48 SEND_SMS: string;
49 RECEIVE_SMS: string;
50 READ_SMS: string;
51 RECEIVE_WAP_PUSH: string;
52 RECEIVE_MMS: string;
53 WRITE_EXTERNAL_STORAGE: string;
54 READ_EXTERNAL_STORAGE: string;
55 BODY_SENSORS: string;
56 };
57 static permissionStatus: {
58 GRANTED: string;
59 DENIED: string;
60 NOT_REQUESTED: string;
61 DENIED_ALWAYS: string;
62 RESTRICTED: string;
63 GRANTED_WHEN_IN_USE: string;
64 };
65 static locationAuthorizationMode: {
66 ALWAYS: string;
67 WHEN_IN_USE: string;
68 };
69 static permissionGroups: {
70 CALENDAR: string[];
71 CAMERA: string[];
72 CONTACTS: string[];
73 LOCATION: string[];
74 MICROPHONE: string[];
75 PHONE: string[];
76 SENSORS: string[];
77 SMS: string[];
78 STORAGE: string[];
79 };
80 static locationMode: {
81 HIGH_ACCURACY: string;
82 DEVICE_ONLY: string;
83 BATTERY_SAVING: string;
84 LOCATION_OFF: string;
85 };
86 static bluetoothState: {
87 UNKNOWN: string;
88 RESETTING: string;
89 UNSUPPORTED: string;
90 UNAUTHORIZED: string;
91 POWERED_OFF: string;
92 POWERED_ON: string;
93 POWERING_OFF: string;
94 POWERING_ON: string;
95 };
96 static NFCState: {
97 UNKNOWN: string;
98 POWERED_OFF: string;
99 POWERED_ON: string;
100 POWERING_ON: string;
101 POWERING_OFF: string;
102 };
103 /**
104 * Checks if app is able to access device location.
105 * @returns {Promise<any>}
106 */
107 static isLocationAvailable(): Promise<any>;
108 /**
109 * 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.
110 * On Android this requires permission. `<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />`
111 * @returns {Promise<any>}
112 */
113 static isWifiAvailable(): Promise<any>;
114 /**
115 * 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
116 * application is authorized to use it.
117 * @returns {Promise<any>}
118 */
119 static isCameraAvailable(): Promise<any>;
120 /**
121 * Checks if the device has Bluetooth capabilities and if so that Bluetooth is switched on (same on Android, iOS and Windows 10 Mobile)
122 * On Android this requires permission <uses-permission android:name="android.permission.BLUETOOTH" />
123 * @returns {Promise<any>}
124 */
125 static isBluetoothAvailable(): Promise<any>;
126 /**
127 * Displays the device location settings to allow user to enable location services/change location mode.
128 */
129 static switchToLocationSettings(): void;
130 /**
131 * Displays mobile settings to allow user to enable mobile data.
132 */
133 static switchToMobileDataSettings(): void;
134 /**
135 * Displays Bluetooth settings to allow user to enable Bluetooth.
136 */
137 static switchToBluetoothSettings(): void;
138 /**
139 * Displays WiFi settings to allow user to enable WiFi.
140 */
141 static switchToWifiSettings(): void;
142 /**
143 * Returns true if the WiFi setting is set to enabled, and is the same as `isWifiAvailable()`
144 * @returns {Promise<boolean>}
145 */
146 static isWifiEnabled(): Promise<boolean>;
147 /**
148 * Enables/disables WiFi on the device.
149 * Requires `ACCESS_WIFI_STATE` and `CHANGE_WIFI_STATE` permissions on Android
150 * @param state {boolean}
151 * @returns {Promise<any>}
152 */
153 static setWifiState(state: boolean): Promise<any>;
154 /**
155 * Enables/disables Bluetooth on the device.
156 * Requires `BLUETOOTH` and `BLUETOOTH_ADMIN` permissions on Android
157 * @param state {boolean}
158 * @returns {Promise<any>}
159 */
160 static setBluetoothState(state: boolean): Promise<any>;
161 /**
162 * 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.
163 * @returns {Promise<boolean>}
164 */
165 static isLocationEnabled(): Promise<boolean>;
166 /**
167 * Checks if the application is authorized to use location.
168 * 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.
169 * @returns {Promise<any>}
170 */
171 static isLocationAuthorized(): Promise<any>;
172 /**
173 * Returns the location authorization status for the application.
174 * @returns {Promise<any>}
175 */
176 static getLocationAuthorizationStatus(): Promise<any>;
177 /**
178 * Returns the location authorization status for the application.
179 * 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.
180 *
181 * mode - (iOS-only / optional) location authorization mode: "always" or "when_in_use". If not specified, defaults to "when_in_use".
182 * @returns {Promise<any>}
183 */
184 static requestLocationAuthorization(mode?: string): Promise<any>;
185 /**
186 * Checks if camera hardware is present on device.
187 * @returns {Promise<any>}
188 */
189 static isCameraPresent(): Promise<any>;
190 /**
191 * Checks if the application is authorized to use the camera.
192 * 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.
193 * @returns {Promise<any>}
194 */
195 static isCameraAuthorized(): Promise<any>;
196 /**
197 * Returns the camera authorization status for the application.
198 * @returns {Promise<any>}
199 */
200 static getCameraAuthorizationStatus(): Promise<any>;
201 /**
202 * Requests camera authorization for the application.
203 * @returns {Promise<any>}
204 */
205 static requestCameraAuthorization(): Promise<any>;
206 /**
207 * Checks if the application is authorized to use the microphone.
208 * @returns {Promise<boolean>}
209 */
210 static isMicrophoneAuthorized(): Promise<boolean>;
211 /**
212 * Returns the microphone authorization status for the application.
213 * @returns {Promise<any>}
214 */
215 static getMicrophoneAuthorizationStatus(): Promise<any>;
216 /**
217 * Requests microphone authorization for the application.
218 * @returns {Promise<any>}
219 */
220 static requestMicrophoneAuthorization(): Promise<any>;
221 /**
222 * Checks if the application is authorized to use contacts (address book).
223 * @returns {Promise<boolean>}
224 */
225 static isContactsAuthorized(): Promise<boolean>;
226 /**
227 * Returns the contacts authorization status for the application.
228 * @returns {Promise<any>}
229 */
230 static getContactsAuthorizationStatus(): Promise<any>;
231 /**
232 * Requests contacts authorization for the application.
233 * @returns {Promise<any>}
234 */
235 static requestContactsAuthorization(): Promise<any>;
236 /**
237 * Checks if the application is authorized to use the calendar.
238 *
239 * Notes for Android:
240 * - 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.
241 *
242 * Notes for iOS:
243 * - This relates to Calendar Events (not Calendar Reminders)
244 * @returns {Promise<boolean>}
245 */
246 static isCalendarAuthorized(): Promise<boolean>;
247 /**
248 * Returns the calendar authorization status for the application.
249 *
250 * Notes for Android:
251 * - 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.
252 *
253 * Notes for iOS:
254 * - This relates to Calendar Events (not Calendar Reminders)
255 *
256 * @returns {Promise<any>}
257 */
258 static getCalendarAuthorizationStatus(): Promise<any>;
259 /**
260 * Requests calendar authorization for the application.
261 *
262 * Notes for iOS:
263 * - 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.
264 * - This relates to Calendar Events (not Calendar Reminders)
265 *
266 * Notes for Android:
267 * - 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.
268 * - This requests permission for `READ_CALENDAR` run-time permission
269 * - Required permissions must be added to `AndroidManifest.xml` as appropriate - see Android permissions: `READ_CALENDAR`, `WRITE_CALENDAR`
270 *
271 * @returns {Promise<any>}
272 */
273 static requestCalendarAuthorization(): Promise<any>;
274 /**
275 * Opens settings page for this app.
276 * On Android, this opens the "App Info" page in the Settings app.
277 * 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.
278 * @returns {Promise<any>}
279 */
280 static switchToSettings(): Promise<any>;
281 /**
282 * Returns the state of Bluetooth on the device.
283 * @returns {Promise<any>}
284 */
285 static getBluetoothState(): Promise<any>;
286 /**
287 * Registers a function to be called when a change in Bluetooth state occurs.
288 * @param handler
289 */
290 static registerBluetoothStateChangeHandler(handler: Function): void;
291 /**
292 * Registers a function to be called when a change in Location state occurs.
293 * @param handler
294 */
295 static registerLocationStateChangeHandler(handler: Function): void;
296 /**
297 * Checks if high-accuracy locations are available to the app from GPS hardware.
298 * 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.
299 * @returns {Promise<boolean>}
300 */
301 static isGpsLocationAvailable(): Promise<boolean>;
302 /**
303 * Checks if location mode is set to return high-accuracy locations from GPS hardware.
304 * Returns true if Location mode is enabled and is set to either:
305 * - Device only = GPS hardware only (high accuracy)
306 * - High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
307 * @returns {Promise<any>}
308 */
309 static isGpsLocationEnabled(): Promise<any>;
310 /**
311 * Checks if low-accuracy locations are available to the app from network triangulation/WiFi access points.
312 * 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.
313 * @returns {Promise<any>}
314 */
315 static isNetworkLocationAvailable(): Promise<any>;
316 /**
317 * Checks if location mode is set to return low-accuracy locations from network triangulation/WiFi access points.
318 * Returns true if Location mode is enabled and is set to either:
319 * - Battery saving = network triangulation and Wifi network IDs (low accuracy)
320 * - High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
321 * @returns {Promise<any>}
322 */
323 static isNetworkLocationEnabled(): Promise<any>;
324 /**
325 * Returns the current location mode setting for the device.
326 * @returns {Promise<any>}
327 */
328 static getLocationMode(): Promise<any>;
329 /**
330 * Returns the current authorisation status for a given permission.
331 * 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.
332 * @param permission
333 * @returns {Promise<any>}
334 */
335 static getPermissionAuthorizationStatus(permission: any): Promise<any>;
336 /**
337 * Returns the current authorisation status for multiple permissions.
338 * 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.
339 * @param permissions
340 * @returns {Promise<any>}
341 */
342 static getPermissionsAuthorizationStatus(permissions: any[]): Promise<any>;
343 /**
344 * Requests app to be granted authorisation for a runtime permission.
345 * 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.
346 * @param permission
347 * @returns {Promise<any>}
348 */
349 static requestRuntimePermission(permission: any): Promise<any>;
350 /**
351 * Requests app to be granted authorisation for multiple runtime permissions.
352 * 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.
353 * @param permissions
354 * @returns {Promise<any>}
355 */
356 static requestRuntimePermissions(permissions: any[]): Promise<any>;
357 /**
358 * Indicates if the plugin is currently requesting a runtime permission via the native API.
359 * Note that only one request can be made concurrently because the native API cannot handle concurrent requests,
360 * so the plugin will invoke the error callback if attempting to make more than one simultaneous request.
361 * Multiple permission requests should be grouped into a single call since the native API is setup to handle batch requests of multiple permission groups.
362 * @returns {boolean}
363 */
364 static isRequestingPermission(): boolean;
365 /**
366 * Registers a function to be called when a runtime permission request has completed.
367 * Pass in a falsey value to de-register the currently registered function.
368 * @param handler {Function}
369 */
370 static registerPermissionRequestCompleteHandler(handler: Function): void;
371 /**
372 * Checks if the device setting for Bluetooth is switched on.
373 * This requires `BLUETOOTH` permission on Android
374 * @returns {Promise<boolean>}
375 */
376 static isBluetoothEnabled(): Promise<boolean>;
377 /**
378 * Checks if the device has Bluetooth capabilities.
379 * @returns {Promise<boolean>}
380 */
381 static hasBluetoothSupport(): Promise<boolean>;
382 /**
383 * Checks if the device has Bluetooth Low Energy (LE) capabilities.
384 * @returns {Promise<boolean>}
385 */
386 static hasBluetoothLESupport(): Promise<boolean>;
387 /**
388 * Checks if the device supports Bluetooth Low Energy (LE) Peripheral mode.
389 * @returns {Promise<boolean>}
390 */
391 static hasBluetoothLEPeripheralSupport(): Promise<boolean>;
392 /**
393 * Checks if the application is authorized to use external storage.
394 * @returns {Promise<boolean>}
395 */
396 static isExternalStorageAuthorized(): Promise<boolean>;
397 /**
398 * CReturns the external storage authorization status for the application.
399 * @returns {Promise<boolean>}
400 */
401 static getExternalStorageAuthorizationStatus(): Promise<any>;
402 /**
403 * Requests external storage authorization for the application.
404 * @returns {Promise<any>}
405 */
406 static requestExternalStorageAuthorization(): Promise<any>;
407 /**
408 * Returns details of external SD card(s): absolute path, is writable, free space.
409 *
410 * The intention of this method is to return the location and details of removable external SD cards.
411 * This differs from the "external directories" returned by cordova-plugin-file which return mount points relating to non-removable (internal) storage.
412 *
413 * Learn more about this method [here](https://github.com/dpa99c/cordova-diagnostic-plugin#getexternalsdcarddetails)
414 *
415 * @returns {Promise<any>}
416 */
417 static getExternalSdCardDetails(): Promise<any>;
418 /**
419 * Switches to the wireless settings page in the Settings app. Allows configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks.
420 */
421 switchToWirelessSettings(): void;
422 /**
423 * Displays NFC settings to allow user to enable NFC.
424 */
425 switchToNFCSettings(): void;
426 /**
427 * Checks if NFC hardware is present on device.
428 * @returns {Promise<boolean>}
429 */
430 static isNFCPresent(): Promise<boolean>;
431 /**
432 * Checks if the device setting for NFC is switched on.
433 * Note: this operation does not require NFC permission in the manifest.
434 * @returns {Promise<boolean>}
435 */
436 static isNFCEnabled(): Promise<boolean>;
437 /**
438 * Checks if NFC is available to the app. Returns true if the device has NFC capabilities AND if NFC setting is switched on.
439 * Note: this operation does not require NFC permission in the manifest.
440 * @returns {Promise<any>}
441 */
442 static isNFCAvailable(): Promise<boolean>;
443 /**
444 * Registers a function to be called when a change in NFC state occurs. Pass in a falsey value to de-register the currently registered function.
445 * @param hander {Function} callback function to be called when NFC state changes
446 * @returns {Promise<any>}
447 */
448 registerNFCStateChangeHandler(handler: Function): void;
449 /**
450 * Checks if the application is authorized to use the Camera Roll in Photos app.
451 * @returns {Promise<boolean>}
452 */
453 static isCameraRollAuthorized(): Promise<boolean>;
454 /**
455 * Returns the authorization status for the application to use the Camera Roll in Photos app.
456 * @returns {Promise<boolean>}
457 */
458 static getCameraRollAuthorizationStatus(): Promise<boolean>;
459 /**
460 * Requests camera roll authorization for the application.
461 * Should only be called if authorization status is NOT_REQUESTED.
462 * Calling it when in any other state will have no effect.
463 * @returns {Promise<any>}
464 */
465 static requestCameraRollAuthorization(): Promise<any>;
466 /**
467 * Checks if remote (push) notifications are enabled.
468 * @returns {Promise<boolean>}
469 */
470 static isRemoteNotificationsEnabled(): Promise<boolean>;
471 /**
472 * Indicates if the app is registered for remote (push) notifications on the device.
473 * @returns {Promise<boolean>}
474 */
475 static isRegisteredForRemoteNotifications(): Promise<boolean>;
476 /**
477 * Indicates the current setting of notification types for the app in the Settings app.
478 * Note: on iOS 8+, if "Allow Notifications" switch is OFF, all types will be returned as disabled.
479 * @returns {Promise<any>}
480 */
481 static getRemoteNotificationTypes(): Promise<any>;
482 /**
483 * Checks if the application is authorized to use reminders.
484 * @returns {Promise<boolean>}
485 */
486 static isRemindersAuthorized(): Promise<boolean>;
487 /**
488 * Returns the reminders authorization status for the application.
489 * @returns {Promise<any>}
490 */
491 static getRemindersAuthorizationStatus(): Promise<any>;
492 /**
493 * Requests reminders authorization for the application.
494 * @returns {Promise<any>}
495 */
496 static requestRemindersAuthorization(): Promise<any>;
497 /**
498 * Checks if the application is authorized for background refresh.
499 * @returns {Promise<boolean>}
500 */
501 static isBackgroundRefreshAuthorized(): Promise<boolean>;
502 /**
503 * Returns the background refresh authorization status for the application.
504 * @returns {Promise<any>}
505 */
506 static getBackgroundRefreshStatus(): Promise<any>;
507 /**
508 * Requests Bluetooth authorization for the application.
509 *
510 * Learn more about this method [here](https://github.com/dpa99c/cordova-diagnostic-plugin#requestbluetoothauthorization)
511 * @return {Promise<any>}
512 */
513 static requestBluetoothAuthorization(): Promise<any>;
514 /**
515 * Checks if motion tracking is available on the current device.
516 * @return {Promise<boolean>}
517 */
518 static isMotionAvailable(): Promise<boolean>;
519 /**
520 * Checks if it's possible to determine the outcome of a motion authorization request on the current device.
521 * There's no direct way to determine if authorization was granted or denied, so the Pedometer API must be used to indirectly determine this:
522 * therefore, if the device supports motion tracking but not Pedometer Event Tracking, the outcome of requesting motion detection cannot be determined.
523 *
524 * @return {Promise<boolean>}
525 */
526 static isMotionRequestOutcomeAvailable(): Promise<boolean>;
527 /**
528 * Requests and checks motion authorization for the application: there is no way to independently request only or check only, so both must be done in one operation.
529 *
530 * Learn more about this method [here](https://github.com/dpa99c/cordova-diagnostic-plugin#requestandcheckmotionauthorization)
531 *
532 * @return {Promise<any>}
533 */
534 static requestAndCheckMotionAuthorization(): Promise<any>;
535}