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:
@@ -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" />
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user