diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-08-03 11:08:44 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2016-08-03 11:38:12 +0000 |
commit | dc1e5850237660df4c64c5ed29e5f7824be6ce81 (patch) | |
tree | 6ae16aa637ecf31955722c7769d89c1809875a92 | |
parent | af14b0d0e3b374f130e580c03dee6af1250cd6e1 (diff) |
Make QtBluetooth Low Energy work when Qt runs as Android service
Change-Id: Ic0814c3f5a65ce9ac9236c41397400fc42abb572
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
-rw-r--r-- | src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java | 10 | ||||
-rw-r--r-- | src/bluetooth/android/lowenergynotificationhub.cpp | 4 |
2 files changed, 7 insertions, 7 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 5150a083..deb70dc0 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 @@ -39,7 +39,6 @@ package org.qtproject.qt5.android.bluetooth; -import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; @@ -48,6 +47,7 @@ import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothProfile; +import android.content.Context; import android.util.Log; import java.util.ArrayList; @@ -70,16 +70,16 @@ public class QtBluetoothLE { @SuppressWarnings({"CanBeFinal", "WeakerAccess"}) long qtObject = 0; @SuppressWarnings("WeakerAccess") - Activity qtactivity = null; + Context qtContext = null; @SuppressWarnings("WeakerAccess") public QtBluetoothLE() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } - public QtBluetoothLE(final String remoteAddress, Activity activity) { + public QtBluetoothLE(final String remoteAddress, Context context) { this(); - qtactivity = activity; + qtContext = context; mRemoteGattAddress = remoteAddress; } @@ -413,7 +413,7 @@ public class QtBluetoothLE { return false; } - mBluetoothGatt = mRemoteGattDevice.connectGatt(qtactivity, false, gattCallback); + mBluetoothGatt = mRemoteGattDevice.connectGatt(qtContext, false, gattCallback); return mBluetoothGatt != null; } diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp index 9ece5bf0..2a6cdce3 100644 --- a/src/bluetooth/android/lowenergynotificationhub.cpp +++ b/src/bluetooth/android/lowenergynotificationhub.cpp @@ -61,9 +61,9 @@ LowEnergyNotificationHub::LowEnergyNotificationHub( const QAndroidJniObject address = QAndroidJniObject::fromString(remote.toString()); jBluetoothLe = QAndroidJniObject("org/qtproject/qt5/android/bluetooth/QtBluetoothLE", - "(Ljava/lang/String;Landroid/app/Activity;)V", + "(Ljava/lang/String;Landroid/content/Context;)V", address.object<jstring>(), - QtAndroidPrivate::activity()); + QtAndroidPrivate::activity() ? QtAndroidPrivate::activity() : QtAndroidPrivate::service()); if (env->ExceptionCheck() || !jBluetoothLe.isValid()) { |