Added check that characteristic is not null before reading it. Displays warning on Logcat if it is null rather than crashing.

This commit is contained in:
Graham Jones
2024-03-25 22:56:56 +00:00
parent cff9d4567c
commit fb59ec6db6
2 changed files with 15 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:versionCode="138" android:versionCode="138"
android:versionName="4.2.4a"> android:versionName="4.2.4b">
<!-- android:allowBackup="false" --> <!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

View File

@@ -368,17 +368,21 @@ public class SdDataSourceBLE extends SdDataSource {
* @param gattCharacteristic - the characteristic to be read. * @param gattCharacteristic - the characteristic to be read.
*/ */
private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) { private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) {
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic); if (gattCharacteristic != null) {
if (retVal) { boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic);
Log.d(TAG, "executeReadCharacteristic - read initiated successfully"); if (retVal) {
Log.d(TAG, "executeReadCharacteristic - read initiated successfully");
} else {
Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying");
mHandler.postDelayed(new Runnable() {
public void run() {
Log.w(TAG, "Executing delayed read of characteristic");
executeReadCharacteristic(gattCharacteristic);
}
}, 100);
}
} else { } else {
Log.d(TAG, "executeReadCharacteristic - read initiation failed - waiting, then re-trying"); Log.i(TAG,"ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything");
mHandler.postDelayed(new Runnable() {
public void run() {
Log.w(TAG, "Executing delayed read of characteristic");
executeReadCharacteristic(gattCharacteristic);
}
}, 100);
} }
} }