cordova.plugins.diagnostic 7.2.2 → 7.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ **v7.2.4**
4
+ * (android & ios) feat: add `isCompassAvailable()` to detect availability of compass for device heading.
5
+ * (doc) update getCameraRollAuthorizationStatus example to include accessLevel parameter
6
+ * Merged from PR [#532](https://github.com/dpa99c/cordova-diagnostic-plugin/pull/532)
7
+ * (android) fix(Diagnostic_Bluethooth.java): Value null at 0 of type org.json.JSONObject$1 cannot be converted to JSONArray
8
+ * Merged from PR [#529](https://github.com/dpa99c/cordova-diagnostic-plugin/pull/529)
9
+
10
+ **v7.2.3**
11
+ * (android) bugfix: dynamically resolve BuildConfig class (and remove hard-coded example app package name) when determining isDebugBuild()
12
+
3
13
  **v7.2.2**
4
14
  * (ios & android) feat: add isDebugBuild()
5
15
  * fix: Separate isMobileDataEnabled() for Android vs isMobileDataAuthorized() for iOS.
package/README.md CHANGED
@@ -22,135 +22,344 @@ Cordova diagnostic plugin [![Latest Stable Version](https://img.shields.io/npm/v
22
22
  - [Usage](#usage)
23
23
  - [Core module](#core-module)
24
24
  - [switchToSettings()](#switchtosettings)
25
+ - [Parameters](#parameters)
26
+ - [Example usage](#example-usage)
25
27
  - [switchToWirelessSettings()](#switchtowirelesssettings)
26
28
  - [switchToMobileDataSettings()](#switchtomobiledatasettings)
27
29
  - [permissionStatus constants](#permissionstatus-constants)
30
+ - [Android](#android)
31
+ - [iOS](#ios)
32
+ - [Example](#example)
28
33
  - [getPermissionAuthorizationStatus()](#getpermissionauthorizationstatus)
34
+ - [Parameters](#parameters-1)
35
+ - [Example usage](#example-usage-1)
29
36
  - [getPermissionsAuthorizationStatus()](#getpermissionsauthorizationstatus)
37
+ - [Parameters](#parameters-2)
38
+ - [Example usage](#example-usage-2)
30
39
  - [requestRuntimePermission()](#requestruntimepermission)
40
+ - [Parameters](#parameters-3)
41
+ - [Example usage](#example-usage-3)
31
42
  - [requestRuntimePermissions()](#requestruntimepermissions)
43
+ - [Parameters](#parameters-4)
44
+ - [Example usage](#example-usage-4)
32
45
  - [isRequestingPermission()](#isrequestingpermission)
46
+ - [Example usage](#example-usage-5)
33
47
  - [registerPermissionRequestCompleteHandler()](#registerpermissionrequestcompletehandler)
48
+ - [Parameters](#parameters-5)
49
+ - [Example usage](#example-usage-6)
34
50
  - [isDataRoamingEnabled()](#isdataroamingenabled)
51
+ - [Parameters](#parameters-6)
52
+ - [Example usage](#example-usage-7)
35
53
  - [isADBModeEnabled()](#isadbmodeenabled)
54
+ - [Parameters](#parameters-7)
55
+ - [Example usage](#example-usage-8)
36
56
  - [isDeviceRooted()](#isdevicerooted)
57
+ - [Parameters](#parameters-8)
58
+ - [Example usage](#example-usage-9)
37
59
  - [isBackgroundRefreshAuthorized()](#isbackgroundrefreshauthorized)
60
+ - [Parameters](#parameters-9)
61
+ - [Example usage](#example-usage-10)
38
62
  - [getBackgroundRefreshStatus()](#getbackgroundrefreshstatus)
63
+ - [Parameters](#parameters-10)
64
+ - [Example usage](#example-usage-11)
39
65
  - [cpuArchitecture constants](#cpuarchitecture-constants)
66
+ - [Android](#android-1)
67
+ - [iOS](#ios-1)
68
+ - [Example usage](#example-usage-12)
40
69
  - [getArchitecture()](#getarchitecture)
70
+ - [Parameters](#parameters-11)
71
+ - [Example usage](#example-usage-13)
41
72
  - [restart()](#restart)
73
+ - [Parameters](#parameters-12)
74
+ - [Example usage](#example-usage-14)
42
75
  - [enableDebug()](#enabledebug)
76
+ - [Parameters](#parameters-13)
77
+ - [Example usage](#example-usage-15)
43
78
  - [getCurrentBatteryLevel()](#getcurrentbatterylevel)
79
+ - [Parameters](#parameters-14)
80
+ - [Example usage](#example-usage-16)
44
81
  - [isAirplaneModeEnabled()](#isairplanemodeenabled)
82
+ - [Parameters](#parameters-15)
83
+ - [Example usage](#example-usage-17)
45
84
  - [isMobileDataEnabled()](#ismobiledataenabled)
85
+ - [Parameters](#parameters-16)
86
+ - [Example usage](#example-usage-18)
46
87
  - [isMobileDataAuthorized()](#ismobiledataauthorized)
88
+ - [Parameters](#parameters-17)
89
+ - [Example usage](#example-usage-19)
47
90
  - [isAccessibilityModeEnabled()](#isaccessibilitymodeenabled)
91
+ - [Parameters](#parameters-18)
92
+ - [Example usage](#example-usage-20)
48
93
  - [isTouchExplorationEnabled()](#istouchexplorationenabled)
94
+ - [Parameters](#parameters-19)
95
+ - [Example usage](#example-usage-21)
49
96
  - [getDeviceOSVersion()](#getdeviceosversion)
97
+ - [Parameters](#parameters-20)
98
+ - [Example usage](#example-usage-22)
50
99
  - [getBuildOSVersion()](#getbuildosversion)
100
+ - [Parameters](#parameters-21)
101
+ - [Example usage](#example-usage-23)
51
102
  - [isDebugBuild()](#isdebugbuild)
103
+ - [Parameters](#parameters-22)
104
+ - [Example usage](#example-usage-24)
52
105
  - [Location module](#location-module)
53
106
  - [locationMode constants](#locationmode-constants)
107
+ - [Values](#values)
108
+ - [Example](#example-1)
54
109
  - [locationAuthorizationMode constants](#locationauthorizationmode-constants)
110
+ - [Values](#values-1)
111
+ - [Example](#example-2)
55
112
  - [locationAccuracyAuthorization constants](#locationaccuracyauthorization-constants)
113
+ - [Values](#values-2)
56
114
  - [isLocationAvailable()](#islocationavailable)
115
+ - [Parameters](#parameters-23)
116
+ - [Example usage](#example-usage-25)
57
117
  - [isLocationEnabled()](#islocationenabled)
118
+ - [Parameters](#parameters-24)
119
+ - [Example usage](#example-usage-26)
58
120
  - [isGpsLocationAvailable()](#isgpslocationavailable)
121
+ - [Parameters](#parameters-25)
122
+ - [Example usage](#example-usage-27)
59
123
  - [isGpsLocationEnabled()](#isgpslocationenabled)
124
+ - [Parameters](#parameters-26)
125
+ - [Example usage](#example-usage-28)
126
+ - [isCompassAvailable()](#iscompassavailable)
127
+ - [Parameters](#parameters-27)
128
+ - [Example usage](#example-usage-29)
60
129
  - [isNetworkLocationAvailable()](#isnetworklocationavailable)
130
+ - [Parameters](#parameters-28)
131
+ - [Example usage](#example-usage-30)
61
132
  - [isNetworkLocationEnabled()](#isnetworklocationenabled)
133
+ - [Parameters](#parameters-29)
134
+ - [Example usage](#example-usage-31)
62
135
  - [getLocationMode()](#getlocationmode)
136
+ - [Parameters](#parameters-30)
137
+ - [Example usage](#example-usage-32)
63
138
  - [isLocationAuthorized()](#islocationauthorized)
139
+ - [Parameters](#parameters-31)
140
+ - [Example usage](#example-usage-33)
64
141
  - [getLocationAuthorizationStatus()](#getlocationauthorizationstatus)
142
+ - [Parameters](#parameters-32)
143
+ - [Example iOS usage](#example-ios-usage)
144
+ - [Example Android usage](#example-android-usage)
65
145
  - [getLocationAuthorizationStatuses()](#getlocationauthorizationstatuses)
146
+ - [Parameters](#parameters-33)
66
147
  - [requestLocationAuthorization()](#requestlocationauthorization)
148
+ - [Parameters](#parameters-34)
149
+ - [Example usage](#example-usage-34)
67
150
  - [registerLocationStateChangeHandler()](#registerlocationstatechangehandler)
151
+ - [Parameters](#parameters-35)
152
+ - [Example usage](#example-usage-35)
68
153
  - [getLocationAccuracyAuthorization()](#getlocationaccuracyauthorization)
154
+ - [Parameters](#parameters-36)
155
+ - [Example usage](#example-usage-36)
69
156
  - [requestTemporaryFullAccuracyAuthorization()](#requesttemporaryfullaccuracyauthorization)
157
+ - [Parameters](#parameters-37)
158
+ - [Example usage](#example-usage-37)
70
159
  - [registerLocationAccuracyAuthorizationChangeHandler()](#registerlocationaccuracyauthorizationchangehandler)
160
+ - [Parameters](#parameters-38)
161
+ - [Example usage](#example-usage-38)
71
162
  - [switchToLocationSettings()](#switchtolocationsettings)
72
163
  - [Bluetooth module](#bluetooth-module)
73
164
  - [bluetoothState constants](#bluetoothstate-constants)
165
+ - [Android](#android-2)
166
+ - [iOS](#ios-2)
167
+ - [Example](#example-3)
74
168
  - [isBluetoothAvailable()](#isbluetoothavailable)
169
+ - [Parameters](#parameters-39)
170
+ - [Example usage](#example-usage-39)
75
171
  - [isBluetoothEnabled()](#isbluetoothenabled)
172
+ - [Parameters](#parameters-40)
173
+ - [Example usage](#example-usage-40)
76
174
  - [hasBluetoothSupport()](#hasbluetoothsupport)
175
+ - [Parameters](#parameters-41)
176
+ - [Example usage](#example-usage-41)
77
177
  - [hasBluetoothLESupport()](#hasbluetoothlesupport)
178
+ - [Parameters](#parameters-42)
179
+ - [Example usage](#example-usage-42)
78
180
  - [hasBluetoothLEPeripheralSupport()](#hasbluetoothleperipheralsupport)
181
+ - [Parameters](#parameters-43)
182
+ - [Example usage](#example-usage-43)
79
183
  - [getBluetoothState()](#getbluetoothstate)
184
+ - [Parameters](#parameters-44)
185
+ - [Example usage](#example-usage-44)
80
186
  - [setBluetoothState()](#setbluetoothstate)
187
+ - [Parameters](#parameters-45)
188
+ - [Example usage](#example-usage-45)
81
189
  - [getBluetoothAuthorizationStatus()](#getbluetoothauthorizationstatus)
190
+ - [Parameters](#parameters-46)
191
+ - [Example usage](#example-usage-46)
82
192
  - [getBluetoothAuthorizationStatuses()](#getbluetoothauthorizationstatuses)
193
+ - [Parameters](#parameters-47)
194
+ - [Example usage](#example-usage-47)
83
195
  - [requestBluetoothAuthorization()](#requestbluetoothauthorization)
196
+ - [Parameters](#parameters-48)
197
+ - [Example usage](#example-usage-48)
84
198
  - [registerBluetoothStateChangeHandler()](#registerbluetoothstatechangehandler)
199
+ - [Parameters](#parameters-49)
200
+ - [Example usage](#example-usage-49)
85
201
  - [switchToBluetoothSettings()](#switchtobluetoothsettings)
86
202
  - [WiFi module](#wifi-module)
87
203
  - [isWifiAvailable()](#iswifiavailable)
204
+ - [Parameters](#parameters-50)
205
+ - [Example usage](#example-usage-50)
88
206
  - [isWifiEnabled()](#iswifienabled)
207
+ - [Parameters](#parameters-51)
208
+ - [Example usage](#example-usage-51)
89
209
  - [setWifiState()](#setwifistate)
210
+ - [Parameters](#parameters-52)
211
+ - [Example usage](#example-usage-52)
90
212
  - [switchToWifiSettings()](#switchtowifisettings)
91
213
  - [Camera module](#camera-module)
92
214
  - [isCameraPresent()](#iscamerapresent)
215
+ - [Parameters](#parameters-53)
216
+ - [Example usage](#example-usage-53)
93
217
  - [isCameraAvailable()](#iscameraavailable)
218
+ - [Parameters](#parameters-54)
219
+ - [Example usage](#example-usage-54)
94
220
  - [isCameraAuthorized()](#iscameraauthorized)
221
+ - [Parameters](#parameters-55)
222
+ - [Example usage](#example-usage-55)
95
223
  - [getCameraAuthorizationStatus()](#getcameraauthorizationstatus)
224
+ - [Parameters](#parameters-56)
225
+ - [Example usage](#example-usage-56)
96
226
  - [getCameraAuthorizationStatuses()](#getcameraauthorizationstatuses)
227
+ - [Parameters](#parameters-57)
228
+ - [Example usage](#example-usage-57)
97
229
  - [requestCameraAuthorization()](#requestcameraauthorization)
230
+ - [Parameters](#parameters-58)
231
+ - [Example usage](#example-usage-58)
98
232
  - [isCameraRollAuthorized()](#iscamerarollauthorized)
233
+ - [Parameters](#parameters-59)
234
+ - [Example usage](#example-usage-59)
99
235
  - [getCameraRollAuthorizationStatus()](#getcamerarollauthorizationstatus)
236
+ - [Parameters](#parameters-60)
237
+ - [Example usage](#example-usage-60)
100
238
  - [requestCameraRollAuthorization()](#requestcamerarollauthorization)
239
+ - [Parameters](#parameters-61)
240
+ - [Example usage](#example-usage-61)
101
241
  - [presentLimitedLibraryPicker()](#presentlimitedlibrarypicker)
242
+ - [Parameters](#parameters-62)
243
+ - [Example usage](#example-usage-62)
102
244
  - [Notifications module](#notifications-module)
103
245
  - [remoteNotificationType constants](#remotenotificationtype-constants)
246
+ - [Example](#example-4)
104
247
  - [isRemoteNotificationsEnabled()](#isremotenotificationsenabled)
248
+ - [Parameters](#parameters-63)
249
+ - [Example usage](#example-usage-63)
105
250
  - [isRegisteredForRemoteNotifications()](#isregisteredforremotenotifications)
251
+ - [Parameters](#parameters-64)
252
+ - [Example usage](#example-usage-64)
106
253
  - [getRemoteNotificationTypes()](#getremotenotificationtypes)
254
+ - [Parameters](#parameters-65)
255
+ - [Example usage](#example-usage-65)
107
256
  - [getRemoteNotificationsAuthorizationStatus()](#getremotenotificationsauthorizationstatus)
257
+ - [Parameters](#parameters-66)
258
+ - [Example usage](#example-usage-66)
108
259
  - [requestRemoteNotificationsAuthorization()](#requestremotenotificationsauthorization)
260
+ - [Parameters](#parameters-67)
261
+ - [Example usage](#example-usage-67)
109
262
  - [switchToNotificationSettings()](#switchtonotificationsettings)
110
263
  - [Microphone module](#microphone-module)
111
264
  - [isMicrophoneAuthorized()](#ismicrophoneauthorized)
265
+ - [Parameters](#parameters-68)
266
+ - [Example usage](#example-usage-68)
112
267
  - [getMicrophoneAuthorizationStatus()](#getmicrophoneauthorizationstatus)
268
+ - [Parameters](#parameters-69)
269
+ - [Example usage](#example-usage-69)
113
270
  - [requestMicrophoneAuthorization()](#requestmicrophoneauthorization)
271
+ - [Parameters](#parameters-70)
272
+ - [Example usage](#example-usage-70)
114
273
  - [Contacts module](#contacts-module)
115
274
  - [isContactsAuthorized()](#iscontactsauthorized)
275
+ - [Parameters](#parameters-71)
276
+ - [Example usage](#example-usage-71)
116
277
  - [getContactsAuthorizationStatus()](#getcontactsauthorizationstatus)
278
+ - [Parameters](#parameters-72)
279
+ - [Example usage](#example-usage-72)
117
280
  - [requestContactsAuthorization()](#requestcontactsauthorization)
281
+ - [Parameters](#parameters-73)
282
+ - [Example usage](#example-usage-73)
118
283
  - [Calendar module](#calendar-module)
119
284
  - [isCalendarAuthorized()](#iscalendarauthorized)
285
+ - [Parameters](#parameters-74)
286
+ - [Example usage](#example-usage-74)
120
287
  - [getCalendarAuthorizationStatus()](#getcalendarauthorizationstatus)
288
+ - [Parameters](#parameters-75)
289
+ - [Example usage](#example-usage-75)
121
290
  - [requestCalendarAuthorization()](#requestcalendarauthorization)
291
+ - [Parameters](#parameters-76)
292
+ - [Example usage](#example-usage-76)
122
293
  - [Reminders module](#reminders-module)
123
294
  - [isRemindersAuthorized()](#isremindersauthorized)
295
+ - [Parameters](#parameters-77)
296
+ - [Example usage](#example-usage-77)
124
297
  - [getRemindersAuthorizationStatus()](#getremindersauthorizationstatus)
298
+ - [Parameters](#parameters-78)
299
+ - [Example usage](#example-usage-78)
125
300
  - [requestRemindersAuthorization()](#requestremindersauthorization)
301
+ - [Parameters](#parameters-79)
302
+ - [Example usage](#example-usage-79)
126
303
  - [Motion module](#motion-module)
127
304
  - [motionStatus constants](#motionstatus-constants)
305
+ - [Example](#example-5)
128
306
  - [isMotionAvailable()](#ismotionavailable)
307
+ - [Parameters](#parameters-80)
308
+ - [Example usage](#example-usage-80)
129
309
  - [isMotionRequestOutcomeAvailable()](#ismotionrequestoutcomeavailable)
310
+ - [Parameters](#parameters-81)
311
+ - [Example usage](#example-usage-81)
130
312
  - [requestMotionAuthorization()](#requestmotionauthorization)
313
+ - [Parameters](#parameters-82)
314
+ - [Example usage](#example-usage-82)
131
315
  - [getMotionAuthorizationStatus()](#getmotionauthorizationstatus)
316
+ - [Parameters](#parameters-83)
317
+ - [Example usage](#example-usage-83)
132
318
  - [NFC module](#nfc-module)
133
319
  - [NFCState constants](#nfcstate-constants)
320
+ - [Values](#values-3)
321
+ - [Example](#example-6)
134
322
  - [isNFCPresent()](#isnfcpresent)
323
+ - [Parameters](#parameters-84)
324
+ - [Example usage](#example-usage-84)
135
325
  - [isNFCEnabled()](#isnfcenabled)
326
+ - [Parameters](#parameters-85)
327
+ - [Example usage](#example-usage-85)
136
328
  - [isNFCAvailable()](#isnfcavailable)
329
+ - [Parameters](#parameters-86)
330
+ - [Example usage](#example-usage-86)
137
331
  - [registerNFCStateChangeHandler()](#registernfcstatechangehandler)
332
+ - [Parameters](#parameters-87)
333
+ - [Example usage](#example-usage-87)
138
334
  - [switchToNFCSettings()](#switchtonfcsettings)
139
335
  - [External storage module](#external-storage-module)
140
336
  - [isExternalStorageAuthorized()](#isexternalstorageauthorized)
337
+ - [Parameters](#parameters-88)
338
+ - [Example usage](#example-usage-88)
141
339
  - [getExternalStorageAuthorizationStatus()](#getexternalstorageauthorizationstatus)
340
+ - [Parameters](#parameters-89)
341
+ - [Example usage](#example-usage-89)
142
342
  - [requestExternalStorageAuthorization()](#requestexternalstorageauthorization)
343
+ - [Parameters](#parameters-90)
344
+ - [Example usage](#example-usage-90)
143
345
  - [getExternalSdCardDetails()](#getexternalsdcarddetails)
346
+ - [Parameters](#parameters-91)
347
+ - [Example usage](#example-usage-91)
144
348
  - [Platform Notes](#platform-notes)
145
- - [Android](#android)
349
+ - [Android](#android-3)
146
350
  - [Android permissions](#android-permissions)
351
+ - [Android runtime permissions](#android-runtime-permissions)
352
+ - ["Dangerous" runtime permissions](#dangerous-runtime-permissions)
353
+ - [Android 11+ runtime permissions](#android-11-runtime-permissions)
354
+ - [Runtime permissions example project](#runtime-permissions-example-project)
355
+ - [Android Camera permissions](#android-camera-permissions)
147
356
  - [Android Auto Backup](#android-auto-backup)
148
- - [iOS](#ios)
357
+ - [iOS](#ios-3)
149
358
  - [iOS usage description messages](#ios-usage-description-messages)
150
359
  - [Example project](#example-project)
151
360
  - [Screenshots](#screenshots)
152
- - [Android](#android-1)
153
- - [iOS](#ios-1)
361
+ - [Android](#android-4)
362
+ - [iOS](#ios-4)
154
363
  - [Release notes](#release-notes)
155
364
  - [Credits](#credits)
156
365
  - [License](#license)
@@ -1317,6 +1526,30 @@ The function is passed a single string parameter containing the error message.
1317
1526
  console.error("The following error occurred: "+error);
1318
1527
  });
1319
1528
 
1529
+ ### isCompassAvailable()
1530
+
1531
+ Platforms: Android & iOS
1532
+
1533
+ Checks if app is able to access device heading.
1534
+
1535
+ cordova.plugins.diagnostic.isCompassAvailable(successCallback, errorCallback);
1536
+
1537
+ #### Parameters
1538
+
1539
+ - {Function} successCallback - The callback which will be called when operation is successful.
1540
+ The function is passed a single boolean parameter which is TRUE if compass is available for use.
1541
+ - {Function} errorCallback - The callback which will be called when operation encounters an error.
1542
+ The function is passed a single string parameter containing the error message.
1543
+
1544
+
1545
+ #### Example usage
1546
+
1547
+ cordova.plugins.diagnostic.isCompassAvailable(function(available){
1548
+ console.log("Compass is " + (available ? "available" : "not available"));
1549
+ }, function(error){
1550
+ console.error("The following error occurred: "+error);
1551
+ });
1552
+
1320
1553
  ### isNetworkLocationAvailable()
1321
1554
 
1322
1555
  Platforms: Android
@@ -2498,7 +2731,7 @@ Platforms: iOS
2498
2731
 
2499
2732
  Returns the authorization status for the application to use the Camera Roll in Photos app.
2500
2733
 
2501
- cordova.plugins.diagnostic.getCameraRollAuthorizationStatus(successCallback, errorCallback);
2734
+ cordova.plugins.diagnostic.getCameraRollAuthorizationStatus(successCallback, errorCallback, accessLevel);
2502
2735
 
2503
2736
  #### Parameters
2504
2737
 
@@ -200,6 +200,16 @@ interface Diagnostic {
200
200
  errorCallback: (error: string) => void
201
201
  ) => void;
202
202
 
203
+ /**
204
+ * Checks if app is able to access device heading.
205
+ * @param successCallback
206
+ * @param errorCallback
207
+ */
208
+ isCompassAvailable: (
209
+ successCallback: (available: boolean) => void,
210
+ errorCallback: (error: string) => void
211
+ ) => void;
212
+
203
213
  /**
204
214
  * Checks if Wifi is available.
205
215
  * On iOS this returns true if the device is connected to a network by WiFi.
@@ -236,6 +246,7 @@ interface Diagnostic {
236
246
  errorCallback: (error: string) => void
237
247
  ) => void;
238
248
 
249
+
239
250
  /**
240
251
  * ANDROID ONLY
241
252
  * Displays the device location settings to allow user to enable location services/change location mode.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.2.2",
2
+ "version": "7.2.4",
3
3
  "name": "cordova.plugins.diagnostic",
4
4
  "cordova_name": "Diagnostic",
5
5
  "description": "Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.",
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova.plugins.diagnostic"
5
- version="7.2.2">
5
+ version="7.2.4">
6
6
 
7
7
  <name>Diagnostic</name>
8
8
  <description>Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.</description>
@@ -64,7 +64,8 @@ import android.view.accessibility.AccessibilityManager;
64
64
 
65
65
  import androidx.core.app.ActivityCompat;
66
66
 
67
- import cordova.plugins.diagnostic.example.BuildConfig;
67
+ import static android.content.Context.CONTEXT_INCLUDE_CODE;
68
+ import static android.content.Context.CONTEXT_IGNORE_SECURITY;
68
69
 
69
70
  /**
70
71
  * Diagnostic plugin implementation for Android
@@ -546,8 +547,11 @@ public class Diagnostic extends CordovaPlugin{
546
547
  return result;
547
548
  }
548
549
 
549
- private boolean isDebugBuild() {
550
- boolean result = BuildConfig.DEBUG;
550
+ private boolean isDebugBuild() throws Exception {
551
+ Context context = this.cordova.getActivity().getApplicationContext();
552
+ ClassLoader classLoader = context.createPackageContext(context.getPackageName(), CONTEXT_INCLUDE_CODE | CONTEXT_IGNORE_SECURITY).getClassLoader();
553
+ Class<?> buildConfigClass = classLoader.loadClass(context.getPackageName() + ".BuildConfig");
554
+ boolean result = buildConfigClass.getField("DEBUG").getBoolean(null);
551
555
  logDebug("Debug build: " + result);
552
556
  return result;
553
557
  }
@@ -327,7 +327,7 @@ public class Diagnostic_Bluetooth extends CordovaPlugin {
327
327
 
328
328
  public void requestBluetoothAuthorization(JSONArray args, CallbackContext callbackContext) throws Exception {
329
329
  JSONArray permissionsToRequest = new JSONArray();
330
- if(args.length() > 0){
330
+ if(args.length() > 0 && args.get(0) instanceof JSONArray){
331
331
  JSONArray specifiedPermissions = args.getJSONArray(0);
332
332
  if(specifiedPermissions.length() > 0){
333
333
  for (int i = 0, size = specifiedPermissions.length(); i < size; i++){
@@ -31,6 +31,8 @@ import org.json.JSONException;
31
31
 
32
32
  import android.content.BroadcastReceiver;
33
33
  import android.content.IntentFilter;
34
+ import android.hardware.Sensor;
35
+ import android.hardware.SensorManager;
34
36
  import android.location.LocationManager;
35
37
  import android.os.Build;
36
38
  import android.util.Log;
@@ -164,7 +166,9 @@ public class Diagnostic_Location extends CordovaPlugin{
164
166
  callbackContext.success(getLocationModeName());
165
167
  } else if(action.equals("requestLocationAuthorization")) {
166
168
  requestLocationAuthorization(args, callbackContext);
167
- }else {
169
+ } else if(action.equals("isCompassAvailable")) {
170
+ callbackContext.success(isCompassAvailable() ? 1 : 0);
171
+ } else {
168
172
  diagnostic.handleError("Invalid action");
169
173
  return false;
170
174
  }
@@ -264,7 +268,13 @@ public class Diagnostic_Location extends CordovaPlugin{
264
268
  callbackContext.sendPluginResult(result);
265
269
  }
266
270
 
267
-
271
+ public boolean isCompassAvailable() {
272
+ SensorManager sensorManager = (SensorManager) this.cordova.getContext().getSystemService(Context.SENSOR_SERVICE);
273
+ boolean result = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null;
274
+ // true if device has a magnetic field sensor (magnetometer)
275
+ diagnostic.logDebug("Compass available: " + result);
276
+ return result;
277
+ }
268
278
 
269
279
  /************
270
280
  * Internals
@@ -27,5 +27,6 @@
27
27
  - (void) getLocationAccuracyAuthorization: (CDVInvokedUrlCommand*)command;
28
28
  - (void) requestLocationAuthorization: (CDVInvokedUrlCommand*)command;
29
29
  - (void) requestTemporaryFullAccuracyAuthorization: (CDVInvokedUrlCommand*)command;
30
+ - (void) isCompassAvailable: (CDVInvokedUrlCommand*)command;
30
31
 
31
32
  @end
@@ -154,6 +154,19 @@ static NSString*const LOG_TAG = @"Diagnostic_Location[native]";
154
154
  }];
155
155
  }
156
156
 
157
+ - (void) isCompassAvailable: (CDVInvokedUrlCommand*)command
158
+ {
159
+ [self.commandDelegate runInBackground:^{
160
+ @try {
161
+ bool isAvailable = [CLLocationManager headingAvailable];
162
+ [diagnostic sendPluginResultBool:isAvailable :command];
163
+ }
164
+ @catch (NSException *exception) {
165
+ [diagnostic handlePluginException:exception :command];
166
+ }
167
+ }];
168
+ }
169
+
157
170
  /********************************/
158
171
  #pragma mark - Internals
159
172
  /********************************/
@@ -825,6 +825,22 @@ var Diagnostic = (function(){
825
825
  }
826
826
  };
827
827
 
828
+ /**
829
+ * Checks if compass is available on the device for use by the app.
830
+ *
831
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
832
+ * This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
833
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
834
+ * This callback function is passed a single string parameter containing the error message.
835
+ */
836
+ Diagnostic.isCompassAvailable = function(successCallback, errorCallback) {
837
+ if(cordova.plugins.diagnostic.location){
838
+ cordova.plugins.diagnostic.location.isCompassAvailable.apply(this, arguments);
839
+ }else{
840
+ throw "Diagnostic Location module is not installed";
841
+ }
842
+ };
843
+
828
844
  /************
829
845
  * WiFi *
830
846
  ************/
@@ -319,6 +319,22 @@ var Diagnostic_Location = (function(){
319
319
  ]);
320
320
  };
321
321
 
322
+ /**
323
+ * Checks if compass is available on the device for use by the app.
324
+ *
325
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
326
+ * This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
327
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
328
+ * This callback function is passed a single string parameter containing the error message.
329
+ */
330
+ Diagnostic_Location.isCompassAvailable = function(successCallback, errorCallback) {
331
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
332
+ errorCallback,
333
+ 'Diagnostic_Location',
334
+ 'isCompassAvailable',
335
+ []);
336
+ };
337
+
322
338
  return Diagnostic_Location;
323
339
  });
324
340
  module.exports = new Diagnostic_Location();
@@ -339,6 +339,22 @@ var Diagnostic = (function(){
339
339
  }
340
340
  };
341
341
 
342
+ /**
343
+ * Checks if compass is available on the device for use by the app.
344
+ *
345
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
346
+ * This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
347
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
348
+ * This callback function is passed a single string parameter containing the error message.
349
+ */
350
+ Diagnostic.isCompassAvailable = function(successCallback, errorCallback) {
351
+ if(cordova.plugins.diagnostic.location){
352
+ cordova.plugins.diagnostic.location.isCompassAvailable.apply(this, arguments);
353
+ }else{
354
+ throw "Diagnostic Location module is not installed";
355
+ }
356
+ };
357
+
342
358
  /**
343
359
  * Requests location authorization for the application.
344
360
  * Authorization can be requested to use location either "when in use" (only in foreground) or "always" (foreground and background).
@@ -231,6 +231,22 @@ var Diagnostic_Location = (function(){
231
231
  Diagnostic_Location._onLocationAccuracyAuthorizationChange = successCallback || function(){};
232
232
  };
233
233
 
234
+ /**
235
+ * Checks if compass is available on the device for use by the app.
236
+ *
237
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
238
+ * This callback function is passed a single boolean parameter which is TRUE if compass is available for use.
239
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
240
+ * This callback function is passed a single string parameter containing the error message.
241
+ */
242
+ Diagnostic_Location.isCompassAvailable = function(successCallback, errorCallback) {
243
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
244
+ errorCallback,
245
+ 'Diagnostic_Location',
246
+ 'isCompassAvailable',
247
+ []);
248
+ };
249
+
234
250
  return Diagnostic_Location;
235
251
  });
236
252
  module.exports = new Diagnostic_Location();