enableGPS uses the check
if (!this.isGPSEnabled())
to determine whether we need to prompt the user to enable location services on the device. isGPSEnabled however returns a Promise, meaning the non-awaited returned value is always truthy, and therefore enableGPS will never actually actually prompt the user to enable location services, even if the promise returned by isGPSEnabled resolves to false
|
public enableGPS(): Promise<void> { |
|
if (Trace.isEnabled()) { |
|
CLog(CLogTypes.info, 'Bluetooth.enableGPS'); |
|
} |
|
return new Promise((resolve, reject) => { |
|
const activity = andApp.foregroundActivity || andApp.startActivity; |
|
if (!this.isGPSEnabled()) { |
|
const onActivityResultHandler = (data: AndroidActivityResultEventData) => { |
|
andApp.off(AndroidApplication.activityResultEvent, onActivityResultHandler); |
|
if (data.requestCode === 0) { |
|
if (this.isGPSEnabled()) { |
|
resolve(); |
|
} else { |
|
reject('GPS not enabled'); |
|
} |
|
} |
|
}; |
|
andApp.on(AndroidApplication.activityResultEvent, onActivityResultHandler); |
|
activity.startActivityForResult(new android.content.Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0); |
|
} else { |
|
resolve(); |
|
} |
|
}); |
|
} |
A simple solution would be to make the promise constructor callback async and adjust the condition to:
if (!(await this.isGPSEnabled()))
The check after receiving the request result from the system on line 1287 also needs to be corrected
|
if (this.isGPSEnabled()) { |
enableGPSuses the checkto determine whether we need to prompt the user to enable location services on the device.
isGPSEnabledhowever returns aPromise, meaning the non-awaited returned value is always truthy, and thereforeenableGPSwill never actually actually prompt the user to enable location services, even if the promise returned byisGPSEnabledresolves tofalseble/src/ble/index.android.ts
Lines 1277 to 1300 in 9820235
A simple solution would be to make the promise constructor callback
asyncand adjust the condition to:The check after receiving the request result from the system on line 1287 also needs to be corrected
ble/src/ble/index.android.ts
Line 1287 in 9820235