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"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="138"
android:versionName="4.2.4a">
android:versionName="4.2.4b">
<!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<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.
*/
private void executeReadCharacteristic(BluetoothGattCharacteristic gattCharacteristic) {
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic);
if (retVal) {
Log.d(TAG, "executeReadCharacteristic - read initiated successfully");
if (gattCharacteristic != null) {
boolean retVal = mBluetoothGatt.readCharacteristic(gattCharacteristic);
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 {
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);
Log.i(TAG,"ExecuteReadCharacteristic() - gatCharacteristic is null, so not doing anything");
}
}