summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-10-29 16:20:13 +0100
committerAlex Blasche <alexander.blasche@digia.com>2014-11-04 14:41:04 +0100
commit1688bbf5c7d4d24018688ee640494c842572d683 (patch)
treec0192722b59e9b9bc852b3b65a60157430ded2a3 /src/android
parentcc5a370e2daad34e05dde7c9c0854ea3bf4eb3fc (diff)
Discover BTLE services on remote device on Android
Change-Id: Ia39e2ad21b0e84cb16a355337370ba82a11b75d0 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
index 6e760012..0fd73613 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
@@ -38,9 +38,13 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
+import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.util.Log;
+import java.util.ArrayList;
+import java.util.List;
+
public class QtBluetoothLE {
private static final String TAG = "QtBluetoothGatt";
private BluetoothAdapter mBluetoothAdapter;
@@ -97,7 +101,6 @@ public class QtBluetoothLE {
public native void leScanResult(long qtObject, BluetoothDevice device, int rssi);
-
private BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
@@ -114,7 +117,7 @@ public class QtBluetoothLE {
}
//This must be in sync with QLowEnergyController::Error
- int errorCode = 0;
+ int errorCode;
switch (status) {
case BluetoothGatt.GATT_SUCCESS:
errorCode = 0; break; //QLowEnergyController::NoError
@@ -124,9 +127,29 @@ public class QtBluetoothLE {
}
leConnectionStateChange(qtObject, errorCode, qLowEnergyController_State);
}
+
+ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
+ //This must be in sync with QLowEnergyController::Error
+ int errorCode;
+ StringBuilder builder = new StringBuilder();
+ switch (status) {
+ case BluetoothGatt.GATT_SUCCESS:
+ errorCode = 0; //QLowEnergyController::NoError
+ final List<BluetoothGattService> services = mBluetoothGatt.getServices();
+ for (BluetoothGattService service: services) {
+ builder.append(service.getUuid().toString() + " "); //space is separator
+ }
+ break;
+ default:
+ Log.w(TAG, "Unhandled error code on onServicesDiscovered: " + status);
+ errorCode = status; break; //TODO deal with all errors
+ }
+ leServicesDiscovered(qtObject, errorCode, builder.toString());
+ }
};
public native void leConnectionStateChange(long qtObject, int wasErrorTransition, int newState);
+ public native void leServicesDiscovered(long qtObject, int errorCode, String uuidList);
public boolean connect() {
if (mBluetoothGatt != null)
@@ -150,5 +173,13 @@ public class QtBluetoothLE {
mBluetoothGatt.disconnect();
}
+ public boolean discoverServices()
+ {
+ if (mBluetoothGatt == null)
+ return false;
+
+ return mBluetoothGatt.discoverServices();
+ }
+
}