Skip to content

Commit

Permalink
Do not crash if bluetoothLeAdvertiser.startAdvertising fails
Browse files Browse the repository at this point in the history
On my phone it throws NullPointerException.
This workaround prevents crash on my phone
when bluetooth is enabled.
This will not fix bluetooth support,
but at least the app is usable over Wi-Fi.
  • Loading branch information
link2xt authored and MathJud committed Mar 25, 2024
1 parent 1822b56 commit 6f0e9fe
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,13 @@ class BleService : LifecycleService() {
settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
settingsBuilder.setConnectable(true)

bluetoothLeAdvertiser!!.startAdvertising(
settingsBuilder.build(), dataBuilder.build(), advertiseCallback
)
try {
bluetoothLeAdvertiser!!.startAdvertising(
settingsBuilder.build(), dataBuilder.build(), advertiseCallback
)
} catch (e: Exception) {
e.printStackTrace()
}
} else {
AppLog.e(
TAG, "Peripheral not supported"
Expand Down

0 comments on commit 6f0e9fe

Please sign in to comment.